我有一个名为ID_No
的属性,并希望对此进行验证:该字符的长度必须为13位数字,且不能多于或少于
我尝试了以下方法:
[Required]
[RegularExpression(@"[0-9]{13}", ErrorMessage = "Invalid ID Number")]
[Range(1000000000000, 9999999999999, ErrorMessage = "ID number cannot be longer than 13 digits")]
[Display(Name = "ID Number")]
public int ID_No { get; set; }
但是它似乎不起作用。一直说“我输入的13位数字”无效。
关于如何使它工作的任何建议或帮助?
答案 0 :(得分:1)
尝试
[Required]
[Display(Name = "ID Number")]
[Range(1000000000000, 9999999999999, ErrorMessage = "ID number cannot be longer than 13 digits")]
[StringLength(13, MinimumLength=13, ErrorMessage = "ID number must be 13 char")]
public long ID_No { get; set; }