I have TextBox on my page. I want to validating this textbox.
The rules are :
- TextBox should not get more than 20 chars
- Only aphanumeric and chars like / – # & ^ spaces to be allowed
how to do using jquery in best way
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The appropriate regex would be:
^[a-zA-Z0-9/#&^\- ]{0,20}$Ask yourself if
A-Zis the right thing. You may be wanting to allow more than that (accented characters for example).Use the JavaScript Unicode Block Range Creator to accommodate the regex for a broader set of allowed input. Check allowed characters with with the handy Javascript RegExp Unicode Character Class Tester.
As always, double check form values on the server side. Relying on JavaScript to do all input checking is dangerous.
For jQuery, have a look at the Valitator plugin, and use code along the lines of: