1

Here's what I've tried so far. Is there something wrong with my Regex?

^(?:|0|[1-9]\\d*)(?:\\.\\d*)?.{10}$

What i did was values must be numbers only and with a maximum number of 10. I have no idea what my code doesn't catch when I input more than 10 numbers.

Rhenz
  • 2,293
  • 1
  • 14
  • 14

4 Answers4

0

You can use following REGEX

/^(\+\d{1,3}[- ]?)?\d{10}$/

For more information use following links:

http://www.regular-expressions.info/numericranges.html

http://www.regexr.com/

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76
0

You want only numeric values from 1 to maximum 10 so this is the REGEX for that:

[0-9]{1,10}

If this is not what you need then let us know a little bit more. You can use https://www.regex101.com to test your REGEX

BlackM
  • 3,927
  • 8
  • 39
  • 69
0

Use this regex, it also supports country code and spacing: /^(\+\d{1,3}[- ]?)?\d{10}$/

atulkhatri
  • 10,896
  • 3
  • 53
  • 89
0

Do you want to have a maximum of 10 numbers only? The below regex works for 8-10 digits in the number

if ($phone =~ /^[0-9]{8,10}$/) {
    print "this is a valid phone number\n";
} else {
    print "not a valid phone number \n";
}
parvezp
  • 191
  • 1
  • 2
  • 5