Skip to content

Instantly share code, notes, and snippets.

@ridvanbaluyos
Created August 11, 2015 10:38
Show Gist options
  • Save ridvanbaluyos/ec339aea3be07e29be65 to your computer and use it in GitHub Desktop.
Save ridvanbaluyos/ec339aea3be07e29be65 to your computer and use it in GitHub Desktop.
Regex for Philippine Numbers
((\+[0-9]{2})|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}
or
((\+63)|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}
will match these:
+63.917.123.4567
+63-917-123-4567
+63 917 123 4567
+639171234567
09171234567
@pellanokeith07
Copy link

Sir not working. I tried to insert this to HTML pattern

@ridvanbaluyos
Copy link
Author

it will work.

<?php
$pattern = "/((\+[0-9]{2})|0)[.\- ]?9[0-9]{2}[.\- ]?[0-9]{3}[.\- ]?[0-9]{4}/";
$numbers = [
	// Valid
	'+63.917.123.4567',
	'+63-917-123-4567' ,
	'+63 917 123 4567',
	'+639171234567',
	'09171234567',
	
	// Invalid
	'aaa',
	'1234567890',
	'0000000000',
	'0917123456A',
	'',
	null,
];

foreach ($numbers as $number) {
	$isValid = preg_match($pattern, $number) ? 'valid' : 'invalid';
	echo $number . ": {$isValid} \n";
}

Will output:

+63.917.123.4567: valid 
+63-917-123-4567: valid 
+63 917 123 4567: valid 
+639171234567: valid 
09171234567: valid 
aaa: invalid 
1234567890: invalid 
0000000000: invalid 
0917123456A: invalid 
: invalid 
: invalid 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment