Roshan
Roshan

Reputation: 717

asp.net validations

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?

Upvotes: 0

Views: 133

Answers (3)

Binoj Antony
Binoj Antony

Reputation: 16186

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#

Upvotes: 2

JP Alioto
JP Alioto

Reputation: 45117

Here is a good example of using a regular expression validator for that. But don't forget O'Dell and Van Damme. :)

Upvotes: 0

Anthony
Anthony

Reputation: 1714

You could use a Regular Expression validator or a Custom Validator.

Upvotes: 0

Related Questions