Is it possible to use ASP.NET MVC 2’s DataAnnotations to only allow characters (no number), or even provide a whitelist of allowed strings? Example?
Is it possible to use ASP.NET MVC 2’s DataAnnotations to only allow characters (no
Share
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.
Use the RegularExpressionAttribute.
Something like
would match a-z upper and lower case and spaces.
A white list would look something like
which should only allow “white” and “list”
\D represents non numeric characters so the above should allow a string with anything but 0-9.
Regular expressions are tricky but there are some helpful testing tools online like:
http://gskinner.com/RegExr/