I want to do validation in asp.net with javascript on age and mobile number. Can you suggest how I could do this?
-
3belongs on sendmethecodez.comBen James– Ben James2010-01-05 15:16:01 +00:00Commented Jan 5, 2010 at 15:16
-
1New user -- cut him some slack. Editing to remove offending "send me the codez" reference.tvanfosson– tvanfosson2010-01-05 15:17:22 +00:00Commented Jan 5, 2010 at 15:17
-
This isn't as stupid as you think, he may want to use the asp.net validators on the client sideChris S– Chris S2010-01-05 15:23:33 +00:00Commented Jan 5, 2010 at 15:23
-
Can you elaborate on your question please?Justin– Justin2010-01-05 15:32:17 +00:00Commented Jan 5, 2010 at 15:32
3 Answers
Check out jQuery and the jQuery validation plugin which will handle these either directly or via the ability to extend the validation rules. That's the code that I would use.
Comments
For the age validation you can use a RangeValidator and for the mobile number you can use a RegularExpression validator.
Comments
- For age you will want a validator that restricts the textbox to numbers only
- For mobile number, you will want numbers only, and also "+" and maybe "-"
I don't want to write a tutorial on validator controls here, but you'll need a RangeValidator* for the age and a RegularExpressionValidator with two regexes and a ValidationSummary control for the error messages. Set EnableClientScript on the two validators to true.
There's a large amount of How Tos on the MSDN site.
* I suggested the wrong one there initially and copied George for RangeValidator