开发者

asp.net mvc datannotion regular expression

开发者 https://www.devze.com 2023-01-04 13:45 出处:网络
how can i create a regular expression forabcABC123/ab开发者_如何学JAVAcABC123 in dataannotion [RegularExpression(

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

精彩评论

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