PhoneFormat.com has a javascript library that has some formatting functions that you could easily drop into your project. It will take whatever number you throw at it and try and convert it to e164 (+ 33252525252), and also format it (+33 2 52 52 52 52)
Try this regex:
/^((\+|00)\d{2})?\d{9}$/
This matches each of your given cases (
+YYXXXXXXXXX
,00YYXXXXXXXXX
,XXXXXXXXX
).Edit: To match your edit:
/^((\+|00)\d{2}|0)\d{9}$/
This is a regex that validates your examples:
PhoneFormat.com has a javascript library that has some formatting functions that you could easily drop into your project. It will take whatever number you throw at it and try and convert it to e164 (+ 33252525252), and also format it (+33 2 52 52 52 52)
The regex to match it would be this
I use http://regexpal.com/ for quick regex testing