Search code examples
javascriptregexphone-number

Regex for international numbers - no space


I am trying to create a regEx that will have an optional '+' as the first character and then after accept all digits, making sure no spaces are allowed.

I have tried the following, but it does not seem to work :

new RegExp(/^\+?\d $/);

Solution

  • Seems like you want something like this,

    new RegExp(/^\+?\d+$/);
    

    Replace space in your regex with +. \d+ matches one or more digits.