Numbers and Spaces - Loose Phone Regex

How to check if a string contains only numbers and spaces using RegEx?

i.e.

  • 021 123 4567 really
  • 0211234567 really
  • 0211 234 567 really

Pretty loose, but it fits my requirements.

Suggestions?

+5
source share
4 answers

How about /^[\d ]+$/? If he needs to start and end with a number, he /^\d[\d ]*\d$/must do it.

+10
source
  • [0-9] <- this means that any digit between 0 and 9
  • [0-9 ] <- this means that any digit from 0 to 9 or a space
  • [0-9 ]{1,} <- this means that any digit from 0 to 9 or a space, 1 or more times
  • [0-9 ]{1,9} <- this means that any digit from 0 to 9 or a space, from 1 to 9 times
+4

n :

^(\s*\d\s*){11}$

n = 11; :

+3

- :

\d*|\s+^[A-Za-z]
0

All Articles