Elina Lulle
Elina Lulle

Reputation: 143

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 $/);

Upvotes: 1

Views: 135

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

Seems like you want something like this,

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

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

Upvotes: 5

Related Questions