[英]regular expression to validate MVC model property
I need a way to validate these 我需要一种方法来验证这些
9 numeric values + V ==> 359123404V or 11 only numeric values 199245781248 9个数值+ V ==> 359123404V或仅11个数值199245781248
i tried below code 我尝试下面的代码
[Display(Name = "NIC Number")]
[Required]
[RegularExpression("[0-9]{11,11}\\d)|([0-9]{9,9}+v")]
public string driverNic { get; set; }
weirdly enough this validates only 13 numeric char input 足够奇怪的是,这仅验证了13个数字字符输入
The correct regex for your case is (^[0-9]{11,11}$)|(^[0-9]{9,9}V$)
. 适合您的情况的正则表达式是
(^[0-9]{11,11}$)|(^[0-9]{9,9}V$)
。
For a full explanation, see regex101.com . 有关完整说明,请参见regex101.com 。 Note that this assumes that the "V" is always uppercase.
注意,这假设“ V”始终为大写。
Also see this C# Fiddle for some test cases. 另请参见此C#小提琴中的一些测试用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.