开发者

asp.net mvc datannotion regular expression

how can i create a regular expression for abcABC123/ab开发者_如何学JAVAcABC123 in dataannotion


[RegularExpression(
    @"^[a-zA-Z0-9]{1,9}/[a-zA-Z0-9]{1,9}$", 
    ErrorMessage = "Invalid format")]
public string Foo { get; set; }

You may adjust as necessary the min and max length of each part and the set of accepted characters.


I'd recommend you have a look at this article on .NET 3.5 DataAnnotations. It has a single example of usage of regular expression for validation. Your's string can be matched by [a-z]{3}[A-Z]{3}[0-9]{3}/[a-z]{3}[A-Z]{3}[0-9]{3} or something more general, like the one posted by Darin.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜