ASP.. NET MVC验证:字符串以000开头,后面跟着另外6个数字 &g



我正在验证一个字符串,它应该是9个字符长,只有数字,必须以000开头。

我创建了以下验证:

[RegularExpression("^[0]{3}*", ErrorMessage="{0} must start with 000 and be numeric")]
[StringLength(9, MinimumLength=9, ErrorMessage = "{0} must be 9 numb long")]
public string Test{get;set;}

有更好的方法吗?

这应该可以正常工作。^000[0-9]{6}$

^ asserts position at start of a line
000 matches the characters 000 literally (case sensitive)
Match a single character present in the list below [0-9]
{6} matches the previous token exactly 6 times
0-9 matches a single character in the range between 0 and 9 (case sensitive)
$ asserts position at the end of a line

Test it here

相关内容

最新更新