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…
- Add one Textbox/area and one RegularExpressionValidator.
- Set properties for RegularExpressionValidator.
- 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
- 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.
- 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.
- 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)