DataAnnotations validation (Regular Expression) in asp.net mvc 4 - razor view

前端 未结 9 2136
甜味超标
甜味超标 2020-11-28 08:12

The DataAnnotations validator not working in asp.net mvc 4 razor view, when using the special characters in the regular expression.

Model:



        
9条回答
  •  爱一瞬间的悲伤
    2020-11-28 08:35

    What browser are you using? I entered your example and tried in both IE8 and Chrome and it validated fine when I typed in the value Sam's

     public class IndexViewModel
     {
        [Required(ErrorMessage="Required")]
        [RegularExpression("^([a-zA-Z0-9 .&'-]+)$", ErrorMessage = "Invalid First Name")]
        public string Name { get; set; }
     }
    

    When I inspect the DOM using IE Developer toolbar and Chrome Developer mode it does not show any special characters.

提交回复
热议问题