3

I want a regular expression for mobile number validation. I have tried below regular expression. If I enter 1 1 1 1 1 1 it will not be accepted. Will you please help to to find what is my mistake in regular expression.

Regular expression is: ^\s*\+?\s*([0-9][\s-]*){6,}$

logi-kal
  • 7,107
  • 6
  • 31
  • 43
  • Have you checked your current regular expression? In Python it gives me this error: "Invalid regular expression: multiple repeat". This seems to be the problem: \s*+ – gil.fernandes Nov 03 '17 at 08:19
  • no it's not duplicate of it. i don't want special char in expression. i even don't want space. – Bansi Sachade Nov 03 '17 at 08:59
  • I assume the mentioned "multiple repeat" isn't really that, but an option to allow a initial `+` with the escape character missing. If it's so, your original regex only needs to escape it, i.e. ` ^\s*\+?\s*([0-9][\s-]*){6,}$`. – SamWhan Nov 15 '17 at 11:51

2 Answers2

3

You can use regex like this ::::

/^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/im

Here i makes the expression case-insensitive and m performs multi-line searches

Or

^([0-9]*){6,}$

Check any number with this regex

Aarsh
  • 2,555
  • 1
  • 14
  • 32
1

My suggestion to match "1 1 1 1 1 1" would be:

^\s*([0-9\s-]){6,}$

The error in your regular expression is the multiple repeat at its beginning:

\s*+

Check the result on pythex.

gil.fernandes
  • 12,978
  • 5
  • 63
  • 76