MVC检验正前pression只有数字?

编程入门 行业动态 更新时间:2024-10-17 15:26:45
本文介绍了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只有数字?

本文发布于:2023-06-05 23:06:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/531169.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字   MVC   pression

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!