Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Validate the German and French phone numbers in MVC

Hi Experts,
Right now I have this expression to validate US phone number. It is working fine.
const string PhoneNumberPattern = @"^(\+?1[\-\. ])?(\(\d{3}\)|\d{3})[\-\. ]?\d{3}[\-\. ]?\d{4}$";

Open in new window

Please help me to write 2 more expression to validate German, French phone numbers.
German - 12 digit format ( 0111 12345678)
French - 10 digit (0x xx xx xx xx)
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Try this validation expression:
Germany
PhoneNumberPattern=@"^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$"

French
PhoneNumberPattern=@"^((\+)33|0)[1-9](\d{2}){4}$"

Open in new window

There is no way to validate phone numbers besides looking them up or calling them.

In an international application you need to store the numbers as E.164 and use country specific formatters to display them.
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Hi David,
Thank you for trying to help me!  The French one is working for me! But the German one should take only 12 digits. But now it is taking 3 digits too.  Please help me to change the expression.
A German phone number can have more than 12 digits.

Doing line based dial telecommunications for over a decade based in Germany, but with dial-ins in the entire world: There is only one storage format, which is E.164 nowadays.

I can remember two weird cases in EU:
- A single city in Italy had a different number scheme.
- Some of the British micro isles where also not the same as the England.

And please believe me, what ever you're trying to do, it has nothing to do with phone number validation. Phone number validation requires that you split out the different parts and check the actual values for correctness. As this is not trivial, there are entire companies offering their services to do.
I really respect your suggestion and trying to dig more into the business rule we need to follow. In the mean time can you please show me one example how to do it?

Thanks a lot!

ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial