I want to make users to enter this pattern in textboxes in asp.net mvc3:
[digit][digit]Code[digit][digit][digit][letter][digit][digit]
I prefer to use annotations but I coul开发者_如何学编程d not find proper one.
You can use the RegularExpressionAttribute attribute
Example taken from MSDN
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
}
public class CustomerMetaData
{
// Allow up to 40 uppercase and lowercase
// characters. Use custom error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "Characters are not allowed.")]
public object FirstName;
// Allow up to 40 uppercase and lowercase
// characters. Use standard error.
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$")]
public object LastName;
}
精彩评论