MVC检验正前pression只有数字? [英] Mvc validation regular expression only numbers?
本文介绍了MVC检验正前pression只有数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试以下code的数字,只验证了MVC的Web应用程序联系人号码验证。
I tried the following code for digits-only validation for a contact number validation in Mvc web app.
[RegularExpression(@"/(^\(\d{10})?)$/", ErrorMessage = "Please enter proper contact details.")]
[Required]
[Display(Name = "Contact No")]
public string ContactNo { get; set; }
但验证前pression是行不通的。
But the validation expression is not working.
有关的联络号码,我想只接受数字。它可以是一个10位移动号码或陆线数。
For the contact number I want to only accept digits. It can be either a 10 digit mobile number or a land-line number.
推荐答案
/ /
是要建立一个正规的前pression字面对象中的JavaScript的方式。在.NET中你不应该使用它。
/ /
is javascript way to build a regular expression literal object. In .NET you should not use it.
请尝试以下操作:
@"^\((\d{10}?)\)$"
或者如果你想整整10位数:
or if you want exactly 10 digits:
@"^(\d{10})$"
这篇关于MVC检验正前pression只有数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文