user2370664
user2370664

Reputation: 423

Phone input mask with optional country code

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

Answers (1)

Quentin Roger
Quentin Roger

Reputation: 6538

I recommend you to use this jquery plugin :

https://github.com/jackocnr/intl-tel-input

$("#phone").intlTelInput();

http://jsfiddle.net/enx8ub4n/

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

Related Questions