RAKESH HOLKAR
RAKESH HOLKAR

Reputation: 2197

Regular expression to check a number with dash and + symbol

  1. numberic value with minmum 10 digit maximumn 15 digit (eg. 9123456789)
  2. 1st character can be + (eg. +919123456789)
  3. Dash symbol "-" can be anywhere but not in first, last and repeated (eg. +91-02-3-456-78-90-21)

Please help me. I have no effective idea in field of regular expression

Upvotes: 0

Views: 143

Answers (1)

Martin Ender
Martin Ender

Reputation: 44259

This is one possible solution:

^\+?(?:\d-?){9,14}\d$

Explanation:

^          # anchor the pattern to the beginning of the string
\+?        # optional literal +
(?:\d-?)   # a digit, followed by an optional hyphen
{9,14}     # 9 to 14 of those
\d         # another digit (to make that 10 to 15, and disallow hyphens at the end)
$          # anchor the pattern to the end of the string

Upvotes: 3

Related Questions