I was browsing through the internet to find a proper javascript regular expression for phone numbers but the ones I find are not the ones I need.
The acceptable phone number type for my case would have to match the following rules:
- May start with
+or0-9 - all rest string is allowed to have only
0-9,-and space (preferably only 1 space between numbers)
I tried so far this: /^\+[\-\d\s]/ but I am not getting the proper result. I’ve tried to read some tutorials but I am very new to this and it seems I am missing something.
An acceptable phone number for example would be: +30 6995 4488551 (spaces allowed) or 0030 6995 4488551 etc.
Any help would be much appreciated! 🙂
Your regex matches anything that starts with a
+followed by a single-, digit or whitespace character. So you will match for example:I suggest you to look at the examples and tutorials on http://www.regular-expressions.info/. As for your telephone numbers a better regex would be:
This would match all valid numbers but also invalid constructions like
+---------or simply+with a trailing space. If you want to be really close to denying a lot of invalid combinations I would suggest you read this, but as you can see the regexes get messy.