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.
精彩评论