Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I validate Mobile/Landline Number formatting using MVC.Net?

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

Any suggestions?

like image 876
Eran Betzalel Avatar asked Nov 28 '25 13:11

Eran Betzalel


1 Answers

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

like image 92
Erik Funkenbusch Avatar answered Nov 30 '25 06:11

Erik Funkenbusch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!