webshim icon indicating copy to clipboard operation
webshim copied to clipboard

How to validate us phone no using patterns?

Open ghost opened this issue 10 years ago • 2 comments
trafficstars

Hi Afarkas,

What is the pattern for validate US Phone nos formats like (123)456-7890, 123-456-7890, 1234567890, (123)-456-7890

This pattern " /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s.]{0,1}[0-9]{3}[-\s.]{0,1}[0-9]{4}$/" is working fine in jquery, but in webshim it is not working.

So can you help me about these? tx for advance.

ghost avatar Apr 21 '15 09:04 ghost

Try the following instead: pattern="[(]{0,1}[0-9]{3}[)]{0,1}[-\s.]{0,1}[0-9]{3}[-\s.]{0,1}[0-9]{4}". HTML5 pattern already transform the string into a regular expression, which must match from start to end.

aFarkas avatar Apr 21 '15 11:04 aFarkas

Working fine for the above formats, but i need to check these types of phone nos also +1 702 123 4567, how to validate?

ghost avatar Apr 21 '15 11:04 ghost