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!

regularexpressionvalidator doesnt trap error

Status
Not open for further replies.

bookouri

IS-IT--Management
Feb 23, 2000
1,464
0
0
US
I have a page with a txt box for a phone number. I added a regularexpressvalidator control to the page and set the control property to point to my phone text box. I then added the validationexpression - ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4} to the validator and set the errormessage to "bad phone" etc.. But I can still put anything into the text box and it will accept it and insert it into my db without throwing any error. I can't figure out what Im missing.

 
I figured out that the validator control is working, in that it displays the error (it was originally placed off the side of the page and i missed it) but i had expected it to stop the data from being passed but i guess i need a different kind of validator to stop the user from actually adding the bad data to the db.

 
validators do just that, validate. they let you know what is invalid. they do not prevent further action. for that you can check the state of the Page.
Code:
private void Button_Click(object sender, EventArgs e)
{
   if(IsValid == false) return;
   Save();
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top