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:
Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim bLoop As Boolean = True
Do While bLoop = True
bLoop = False
Dim ctl As Control
For Each ctl In Me.Controls 'checks to see if all required textboxes have been completed
If [B]Trim([COLOR=RoyalBlue]ctl.Text[/COLOR]) [/B] = "" And TypeOf ctl Is TextBox Then
Msgbox("Please make entry for " & ctl.ID.ToString)
bLoop = True
End If
Next
Select Case False 'check for numeric entry
Case CheckNumeric(txtmobile.Text)
txtmobile.Text = Not (IsNumeric("Mobile"))
bLoop = True
Case CheckNumeric(HomeTel.Text)
HomeTel.Text = Not (IsNumeric("HomeTel"))
bLoop = True
End Select
Loop
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.
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:
If Not ctl Is Nothing Then
If ctl.Text.Length = 0 Then
(validator + ID).ToString.text = ("Please make entry for " & ctl.ID.ToString))
End If
But its not the right syntax. can someone please correct me or guide for some insturctions on how it works.
Thanks
Re: Check if Textbox input is numeric
Why aren't you doing this at design time, on the page itself?
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??
Re: Check if Textbox input is numeric
Re: Check if Textbox input is numeric
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??
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
Re: Check if Textbox input is numeric
The regular expression would look like:
[\w\_\.]+@[\w\_]+.(?:com|org|net)