我正在尝试使用以下正则表达式验证特殊字符。它正确地阻止了特殊字符,但它也阻止了数字。有没有办法让它不输错数字?
[Required(ErrorMessage = "Enter Project Title")]
[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage = "special characters are not allowed.")]
public string Title { get; set; }
答案 0 :(得分:3)
添加0-9应该可以解决问题。
[RegularExpression(@"^[0-9a-zA-Z''-'\s]{1,40}$",
ErrorMessage = "special characters are not allowed.")]