Results 1 to 10 of 10

Thread: Check if Textbox input is numeric

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Check if Textbox input is numeric

    Hi ,

    I am trying to check for a numeric input. I had this procedure in windows app and Im trying to put it in web but Im getting an error on
    ctl.text in the code below

    any ideas how I can correct this pleased.. Many thanks


    VB Code:
    1. Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click
    2.         Dim bLoop As Boolean = True
    3.         Do While bLoop = True
    4.             bLoop = False
    5.             Dim ctl As Control
    6.             For Each ctl In Me.Controls   'checks to see if all required textboxes have been completed
    7.                 If [B]Trim([COLOR=RoyalBlue]ctl.Text[/COLOR]) [/B] = "" And TypeOf ctl Is TextBox Then
    8.                      Msgbox("Please make entry for " & ctl.ID.ToString)
    9.                     bLoop = True
    10.                 End If
    11.             Next
    12.             Select Case False    'check for numeric entry
    13.                 Case CheckNumeric(txtmobile.Text)
    14.                     txtmobile.Text = Not (IsNumeric("Mobile"))
    15.                     bLoop = True
    16.                 Case CheckNumeric(HomeTel.Text)
    17.                     HomeTel.Text = Not (IsNumeric("HomeTel"))
    18.                     bLoop = True
    19.             End Select
    20.         Loop
    Last edited by angelica; Oct 6th, 2005 at 05:27 PM.

  2. #2
    Addicted Member
    Join Date
    Aug 2004
    Location
    Cape Town, South Africa
    Posts
    149

    Re: Check if Textbox input is numeric

    I'm guessing its a build error? Its probably because the property "Text" does not belong to a generic control.

    Rather than declaring ctl as a control, declare it as a textbox.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Check if Textbox input is numeric

    hi,

    It's the case alright, clt.text is not a member.

    Now I thought of insstead giving a message in a RequiredFieldValidator. I know you match it with the ControlToValidate. I need to know how to use them in something like this:


    VB Code:
    1. If Not ctl Is Nothing Then
    2.                 If ctl.Text.Length = 0 Then
    3.                     (validator + ID).ToString.text = ("Please make entry for " & ctl.ID.ToString))
    4.                 End If


    But its not the right syntax. can someone please correct me or guide for some insturctions on how it works.

    Thanks

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Check if Textbox input is numeric

    Why aren't you doing this at design time, on the page itself?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Check if Textbox input is numeric

    Mendhak, I dont know how to use the blessed required field validation! and I also want to check if all my textboxes are null, how can I??

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Check if Textbox input is numeric

    Thanks for the info

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Check if Textbox input is numeric

    Mendhak,

    Those tutorials are very good. I have done a validation to my textboxes and they are working fine. There is two thing I need to clear but

    1. How do I validate that its a valid email address ?

    2. Since I have done these validations the data is not going into my database any longer. Am I missing something??

  9. #9
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: Check if Textbox input is numeric

    Angelica,

    You can write a regular expression to validate your email addresses

    or just look for the basic construsctors i.e. must contain the @ then a dot(.)
    if you do a search on this forum or the web I'm sure you'll find some prewritten ones

    showThread

  10. #10
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: Check if Textbox input is numeric

    The regular expression would look like:

    [\w\_\.]+@[\w\_]+.(?:com|org|net)
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width