Reputation: 143
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
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