简体   繁体   English

asp.net正则表达式检查不正确

[英]asp.net regular expression doesn't check correctly

I have a simple regularExpression which checks to see if the given information is only 4 digits long and only contains digits. 我有一个简单的regularExpression,它可以检查给定的信息是否只有4位数字长且仅包含数字。 I have something that works but it doesn't allow the user to start the first digit off as a 0, any ideas why? 我有一些有效的方法,但是它不允许用户将第一个数字从0开始,有什么想法吗? Here is my regularexpression 这是我的正则表达式

[RegularExpression("^[0-9]{4,4}$", ErrorMessage = "PIN did not follow the correct format of 4-digits")]

More information 更多信息

[Required(ErrorMessage = "Please input your 4 digit pin.")] [RegularExpression("^[0-9]{4,4}$", ErrorMessage = "PIN did not follow the correct format of 4-digits")] [Display(Name = "PIN")] public long PIN { get; [Required(ErrorMessage =“请输入您的4位数密码。”)] [RegularExpression(“ ^ [0-9] {4,4} $”,ErrorMessage =“ PIN格式不正确,为4位数”) ] [Display(Name =“ PIN”)]公共长PIN {get; set; 组; } }

If you use regexpal the regular expression is fine with numbers starting with zero. 如果您使用regexpal正则表达式是细跟从零开始编号。 It looks like the problem is related to another issue. 该问题似乎与另一个问题有关。

A long cannot start with zero - PIN should be of type string . long不能以零开头-PIN的类型应为string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM