我如何可以验证手机/座机号码使用MVC.Net格式化? [英] How can I validate Mobile/Landline Number formatting using MVC.Net?

查看:142
本文介绍了我如何可以验证手机/座机号码使用MVC.Net格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pretty简单的问题 - 验证使用数据注释国际移动/固定电话号码

有什么建议?


解决方案

有没有单一的国际电话号码的标准,但你可以做一些验证。例如:

<$p$p><$c$c>[RegularEx$p$pssion(@\"^([\\+]|0)[(\\s]{0,1}[2-9][0-9]{0,2}[\\s-)]{0,2}[0-9][0-9][0-9\\s-]*[0-9]$\")]

这允许,例如: 044 123-456 +2 12-12456 +(234)56-56-452 。在这里看到更多种常规的前pressions的电话号码:

http://regexlib.com/Search.aspx?k=phone+number&c=0&m=0&ps=20&p=12

Pretty simple question - validating International Mobile/Landline Number using Data Annotations.

Any suggestions?

解决方案

There is no single "international" phone number standard, but you can do some validation. For example:

[RegularExpression(@"^([\+]|0)[(\s]{0,1}[2-9][0-9]{0,2}[\s-)]{0,2}[0-9][0-9][0-9\s-]*[0-9]$")]

This allows, for example: 044 123-456, +2 12-12456, +(234) 56-56-452. See here for more kinds of regular expressions for phone numbers:

http://regexlib.com/Search.aspx?k=phone+number&c=0&m=0&ps=20&p=12

这篇关于我如何可以验证手机/座机号码使用MVC.Net格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆