Reputation: 423
I would like to create an input mask for phone numbers. The majority of the phone numbers will look like (123) 456 - 7890. I would like an optional country code and extension to be accepted when applicable.
(123) 456 -7890 x1234
+1 (123) 456 - 7890
+1 (123) 456 -7890 x1234
Am i able to do this with regex and jquery?
Upvotes: 1
Views: 20977
Reputation: 6538
I recommend you to use this jquery plugin :
https://github.com/jackocnr/intl-tel-input
$("#phone").intlTelInput();
With an example to validate user input :
https://intl-tel-input.com/node_modules/intl-tel-input/examples/gen/is-valid-number.html
Upvotes: 2