Created
March 19, 2015 13:47
-
-
Save jeffreyvr/e2bcabeb83ddf12e3de0 to your computer and use it in GitHub Desktop.
Validate Dutch Phone Number
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
<?php | |
/** | |
* Validate Dutch Phone number | |
* | |
* Can be a local or mobile phone number. | |
*/ | |
function validate_dutch_phone_number( $phone_number ){ | |
if ( preg_match( "/^(\+|00|0)(31\s?)?(6[\s-]?[1-9][0-9]{7}|[1-9][0-9][\s-]?[1-9][0-9]{6}|[1-9][0-9]{2}[\s-]?[1-9][0-9]{5})$/", $phone_number ) ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
// Example of valid number | |
if( validate_dutch_phone_number( '0612345678' ) ) { | |
echo 'Your number is <strong>valid</strong>.'; | |
} else { | |
echo 'Your number is <strong>invalid</strong>.'; | |
} | |
// Example of invalid number | |
if( validate_dutch_phone_number( '0001' ) ) { | |
echo 'Your number is <strong>valid</strong>.'; | |
} else { | |
echo 'Your number is <strong>invalid</strong>.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment