i have this one so far used for validation a phone number in my form:
/^\s*\+?\s*([0-9]+\s*)+\s*(\((\+?[0-9]+\s*)+\))?\s*[0-9-\s]*[0-9]\s*$/
it works for like those numbers : +021 (+12) 113-2145 but i need to add an extension to the end of it like this : +021 (+12) 113-2145 x 123 so how can i add the char x and after that the digits?
also the spaces between the x and digits should be optional like in my code above.
any idea? thanks!
First off, you could replace all instances of
[0-9]with the shorter\d. (for decimal digit)Then, add this to the original regex:
So it would be
Edit: Made the extension optional
Edit 2: Used
\dinstead of[0-9]