开发者

validation of specific string pattern in entity framework

开发者 https://www.devze.com 2023-03-13 17:11 出处:网络
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 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消