Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RegExp phone number with mandatory space

Would love to know a regExp to validate a phone number.
Rules:

  • It must start with +
  • It must have one and only once space in it
  • It must have only numbers and no other special chars other than the space
+31 45847362 ->> ok
+1234 45847362 ->> ok
+1234 458473 62 ->> no
+3145847362 ->> no
045847362 ->> no
+31-45847362 ->> no
+(31) 45847362 ->> no
+(31)45847362 ->> no

I have this but the space is not mandatory, not sure why. I though every char was mandatory in regexp

/^[+]*[{0,1}[0-9]{0,1}[\s./0-9]*$/;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Would this (in PCRE syntax) plus a length check work?

^\+[0-9]*\s[0-9]*$

(then check for valid length of phone number plus a space)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading