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 has built in support for telephone numbers:
[DataType(DataType.PhoneNumber)]
public string Phone { get; set; }
See the MSDN reference page for more information on the validatation types available: DataType Enumeration.
来源:https://stackoverflow.com/questions/8028735/how-can-i-validate-mobile-landline-number-formatting-using-mvc-net