Created
February 28, 2016 21:49
-
-
Save 5iDS/598e523b98340183be21 to your computer and use it in GitHub Desktop.
Matches South African telephone/mobile numbers, with or without the country code. Can also include spaces or hyphens between values. Doesn't match brackets around the area code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Matches: 0111231234 | 011 123 1234 | 011-123-1234 | 0821231234 | +27821231234 | +2782-123-1234 | +2782 123 1234 | 27111231234 | 2711 123 1234 | 2711-123-1234 | |
* Non-Matches: (011)1231234 | (+2711) 123 1234 | (011) 123-1234 | |
/**/ | |
var pattern2 = new RegExp(/^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$/); | |
console.log( pattern2.test( '+27134622241' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It fails in one condition.
var pattern2 = new RegExp(/^((?:+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$/);
console.log( pattern2.test( '0000000000' ) );
Can you please improve it ?