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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a CustomValidator that works like a RegularExpressionValidator

Status
Not open for further replies.

sbushway

Programmer
Jan 27, 2003
58
US
Hi,
Is there a way to create a CustomValidator that works like a RegularExpressionValidator?

I've got a web application with a RadioButtonList, four textboxes, and a submit button. Depending on which radiobutton is checked, different textboxes must be filled in. (ie: if the first radiobutton is checked, the first two textboxes must be filled in; if the second radiobutton is checked, the second two textboxes must be filled in)

A while ago, I needed a RequiredFieldValidator (if the first rb is checked, I needed to make sure the first two textboxes weren't blank). Because this check was conditional, I had to make a CustomValidator that worked the same as a RFV since I couldn't make a conditional RFV.

Now I have a problem where, if the user clicks the first radiobutton, I need to make sure the user only entered alphanumeric data. Since I can't make the RegularExpressionValidator conditional, I figured I'd make it a Custom Validator. I just don't know how to check for a regular expression in my function.

I saw something like this:
If(me.txtAST.Text Like "[0-9A-Za-z]")
' Alphanumeric data
Else
' Nonalphanumeric data

But the IF statement will fail no matter what data I enter (00001, 00002, 0001A, etc). I'd like it to work the same way as if I had a RegularExpressionValidator with the ValidationExpression set to "\w{5}"

Any ideas??

Thanks in advance,
Suzanne
 
And my question would be...

why build something that exists?

Is this for client side validation?
If so vbscript has a regexp and it falls under dhtml
(of course then it is an IE solution but...)
java I think also has native support for fegexp but I don't do java. With Java and a heap of coding to handle all types of browsers..or heck just do it wiht server side and hope everyone has a real inet connection.

Rob

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top