开发者

Zip Code validation using MVC2 in asp.net mvc

 [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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜