I want to add a validation control to check if the first name and last name of a person entered consists of characters from A-Z and not any special characters and numbers? How to do it?
+1
A:
use a regular expression validator and put the [a-zA-Z]
as the reg ex to validate.
If you want support for hyphen and underscore then put [a-zA-Z_\-]
<asp:RegularExpressionValidator id="revalApha" runat="server"
ControlToValidate="TextBox1" ValidationExpression="[a-zA-Z]+$"
ErrorMessage="Only Alphabets allowed"> </asp:RegularExpressionValidator>
I will advice against the custom validator since you need to write a function both in javascript and in c#
Binoj Antony
2009-04-22 05:25:55
A:
Here is a good example of using a regular expression validator for that. But don't forget O'Dell and Van Damme. :)
JP Alioto
2009-04-22 05:27:46