changing number regex to allow spaces for phone number
This is an open discussion with 3 replies, filed under General.
Search
I'm still learning regex myself, but here's how I'd do it:
Assuming you don't want negative phone numbers or phone numbers with dots in them then you can probably go with something like /^[\s\d]+$/
/ /
regex qualifiers^
start of string$
end of string[]
set of single characters to match (multiple characters are "or"ed)\s
whitespace\d
digits+
one or more of the preceding character or set
However, this is super simple, it will match any set of digits with whitespace so
1 2 0000000003456789
is valid in this case. I'm sure someone will be along to provide a more rigid version at some point!
edit: note trailing and leading spaces
Thanks for the clear explanation, it's working perfectly!
I am gonna use this mini course as a basis for future use cases.
Cheers
No problem.
Someone linked RegExr on here at some point, great for testing this sort of stuff. Also there's the wikipedia article on Regex and a fairly comprehensive .info site that I use for reference.
Create an account or sign in to comment.
Hi,
The title pretty much says it;
How to change the 'number' regular expression on the text input field, so it allows whitespaces as well, to make the validation a bit more tolerant on phone numbers?
Cheers