开发者

Validating a users phone number on a global scale using MVC3

开发者 https://www.devze.com 2023-04-12 15:17 出处:网络
Im working on an mvc3 application that will be deployed globally and have a question about phone numbers and validation.

Im working on an mvc3 application that will be deployed globally and have a question about phone numbers and validation.

I want to display a textbox that allows customers to insert their phone number correctly based on the machines settings.

I know I can apply all of my regex's onto the model's PhoneNumber field.

If a user is coming from the US vs the UK there are 2 different regexs to be used.

Lets say a US based user inserts an invalid phone number h开发者_如何学运维ow can I tell the application only to validate the phone number using the US format based on the users culture not against the entire range of regex's?

I dont want the user to be told that his/her phone number is not formatted in UK format as that means nothing to them.

Hope this makes sense.


There are a lot more than two regexes.

For the UK alone there are are getting on for 10 or more different formats for telephone numbers and that doesn't take into account the different ways people can (and do) group the digits as well.

My answer to a different question shows the different formats.

You're best approach is probably to use other data on the form to try to validate the phone number rather than analysing the number itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消