Regular expression for mobile number error in case 1 1 1 1 1 1

Viewed 83

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,}$"

2 Answers

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

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.

Related