开发者

Zip Code validation using MVC2 in asp.net mvc

开发者 https://www.devze.com 2023-03-06 07:21 出处:网络
[Required(ErrorMessage = \"Please Enter AccountZip Code!\")] [RegularExpression(@\"/(^\\d{5}(-\\d{4})?$/\", ErrorMessage = \" Zip code must be 5 characters length\")]
 [Required(ErrorMessage = "Please Enter AccountZip Code!")]
            [RegularExpression(@"/(^\d{5}(-\d{4})?$/", ErrorMessage = " Zip code must be 5 characters length")] 
            public string AccountZip { get; set; }

I did regularexpression for Zip code validation I am getting this Error 开发者_运维问答Message

parsing "/(^\d{5}(-\d{4})?$/" - Not enough )'s.

Can any body help me out?

Thanks


Your regex looks like it was pulled from a javascript sample. Try this:

@"^\d{5}(-\d{4})?$"


You need one more ( at the end as follows:

RegularExpression(@"/(^\d{5}(-\d{4})?)$/"


Great job @"\b(0?[0-9][0-9][0-9][0-9][0-9])\b" actually works and validates both numeric and length

0

精彩评论

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

关注公众号