Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Validator

Status
Not open for further replies.

wahoo02

Programmer
Sep 15, 2003
5
0
0
US
I'm currently using a form that uses a Regular Expression Validator for validating phone # information. After testing the validator out, I found that the validator will catch errors where 1, and 2 numbers are inputted. It won't however catch the instance where the user doesn't put anything. I know that there is a RequiredFieldValidator in ASP.NET, but doing regular expression of \d{3} should catch all errors of 0 input,1 input, or 2 input. Heres one of the validator calls, any advice on if I goofed up, or going about this the wrong way would be appreciated.

<asp:RegularExpressionValidator runat=&quot;server&quot;
id=&quot;prefix&quot; ControlToValidate=&quot;textprefix&quot;
ValidationExpression=&quot;\d{3}&quot;
Error Message =&quot;*&quot;
CausesValidation = &quot;False&quot; />

Thanks
wahoo02

[spidey]
 
I would like you to know one thing which I came to know recently.

All Validators except RegularExpression validator will supress any kind of validation if the data is null.

Even I had the same doubt
 
You need a RequiredFieldValidator as well as your RegularExpressionValidator. You would think that it would work with just the regular expression, but that's just the way the validation controls work.


lfc77
 
Thanks for the feedback guys, I was driving myself crazy on this one. I guess i'll have to use the resort to using the RequiredFiedValidator too.

[spidey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top