Search This Blog

Regular Expression for Restricting Characters

If you are getting the value from the user on a text box/area or something and you don't want user to allow user to enter some characters like html tags(<,>,* etc).

Then it is better to use regular expression which will cause Page Invalid .

For that steps are…

  1. Add one Textbox/area and one RegularExpressionValidator.
  2. Set properties for RegularExpressionValidator.
  3. In ValidationExpression property set value "[^<>/?&{};#]+".

Just Over. This will not allow user to enter the symbols given above. (< , > , / , ? , & , { , } , ; , # ).

You can add or remove other text/symbols/numbers to the above list.

If you want to allow user to enter the characters from certain range then    

  1. In ValidationExpression property set value "^[a-zA-Z]*$".

This will allow user to enter only the characters from a to z and A to Z.

  1. In ValidationExpression property set value "^[a-zA-Z0-9]*$" .

This will allow user to enter only the characters from a to z and A to Z and also 0 to 9.

  1. In ValidationExpression property set value "^[a-zA-Z .]*$" .

This will allow user to enter only the characters from a to z and A to Z Space and Dot. (Ex Mr. Xyz Mno)

Link Within Related Posts Plugin for WordPress, Blogger...
There was an error in this gadget