1

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?

user2370664
  • 381
  • 5
  • 8
  • 30
  • Dupe of this? https://stackoverflow.com/questions/11633726/phone-mask-with-jquery-and-masked-input-plugin – mplungjan Jan 15 '18 at 13:55

1 Answers1

2

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

Quentin Roger
  • 6,410
  • 2
  • 23
  • 36
  • 1
    I would like to use jquery.mask. I just need help with the regular expression to accomplish the examples i provided above – user2370664 Jan 17 '18 at 15:01