how to validate a textBox for 0-9 Digits only

R

RSB

Hi every one,
how do i check the text box that one can only enter the numeric Digits. i
have the maxlength of the Text box as 6. so one way i thought was to
validate the Number between 0 and 999999. so is there any other way ..say
using the RegularExpressionValidator control.

Thanks
RSB
 
R

Raterus

Use a comparevalidator

Dim blah As CompareValidator

blah.Operator = ValidationCompareOperator.DataTypeCheck

blah.Type = ValidationDataType.Integer
 
G

Guest

You could also have used something along the lines of

<asp:RegularExpressionValidator id="Validator1" ASPClass="RegularExpressionValidator" ControlToValidate="YouTextField" ValidationExpression="[0-9]{6,}"runat="server"></asp:RequiredFieldValidator>
 
G

Guest

Sorry, I typed in the wrong closing tag obviously...closing tag should be
</asp:RegularExpressionValidator>
--
Edmond Goon

"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Einstein


Edmond Goon said:
You could also have used something along the lines of

<asp:RegularExpressionValidator id="Validator1" ASPClass="RegularExpressionValidator" ControlToValidate="YouTextField" ValidationExpression="[0-9]{6,}"runat="server"></asp:RequiredFieldValidator>
--
Edmond Goon

"As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality." - Einstein


RSB said:
Hi every one,
how do i check the text box that one can only enter the numeric Digits. i
have the maxlength of the Text box as 6. so one way i thought was to
validate the Number between 0 and 999999. so is there any other way ..say
using the RegularExpressionValidator control.

Thanks
RSB
 
A

Alan Ferrandiz Langley

You could use a RegularExpressionValidator along with a RequiredFieldValidator to check for blank spaces, the validation expression could be something like:

RegularExpressionValidator1.ValidationExpression = "^\d*[0-9]$"

so that you accept only digits from 0 to 9

Hope this helps

Alan Ferrandiz L.
MCT, MCDBA, MCSD
MSF Practitioner
 
R

RSB

Ok i tried this and it worked ValidationExpression="\d*"

Hi every one,
how do i check the text box that one can only enter the numeric Digits. i
have the maxlength of the Text box as 6. so one way i thought was to
validate the Number between 0 and 999999. so is there any other way ..say
using the RegularExpressionValidator control.

Thanks
RSB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top