-2

How can i validate a phone number with plus sign optional only at the beginning and after that any number of digits with number only.

I tried this:-

/^\+(?:[\d]*)$/

How will be the modification

VeNaToR
  • 29
  • 1
  • 7
  • possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Biffen Apr 10 '15 at 08:26

1 Answers1

3
/^\+?(?:[\d]*)$/

The questionmark tells that the plus sign can be there or not. However, your expression can be optimized quite a bit:

/^\+?\d+$/ 

I changed the * to a + as the expression would match just a plus sign. \d* suggests that it should match 0 or more digits.

Here's a demo on Regexr.

rdiz
  • 5,627
  • 1
  • 25
  • 36
  • 1
    There's a lot of unnecessary stuff in there, the shortened version would be `/^\+?\d*$/`. – Biffen Apr 10 '15 at 07:20