Title |
Test
Find
Validate ZA Phone Numbers
|
Expression |
^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$ |
Description |
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, but that would be easy to add in. Hope it helps someone... |
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 |
Author |
Rating:
Rory Cottle
|
Source |
|
Your Rating |
|
Title: Doesn't allow spaces
Name: Richard
Date: 9/19/2016 8:29:49 AM
Comment:
This doesn't match: +2782 123 1234
But you can fix it in Javascript by first removing spaces:
export function isValidPhone(input: string): boolean {
const phoneRegex = /^((?:\+27|27)|0)(\d{2})-?(\d{3})-?(\d{4})$/;
return phoneRegex.test(input.replace(/\s/g, ''));
}
Title: Spaces
Name: Marc
Date: 8/18/2010 8:42:54 AM
Comment:
Hi,
The expression didn't accept spaces. Try
^((?:\+27|27)|0)(\d{2})(?:-| )?(\d{3})(?:-| )?(\d{4})$
Cheers.
Title: Spaces
Name: Marc
Date: 8/18/2010 8:42:16 AM
Comment:
Hi,
The expression didn't accept spaces. Try
^((?:\+27|27)|0)(\d{2})(?:-| )?(\d{3})(?:-| )?(\d{4})$
Cheers.