Forked from sepiariver/FormIt.validator.isPhone.snippet.php
Created
December 21, 2017 12:17
-
-
Save Burick/ca890eeaa5c6fdaae87e7117dd652cc2 to your computer and use it in GitHub Desktop.
FormIt validator for phone number based on: https://regex101.com/r/xX3hO8/1
This file contains hidden or 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 | |
$success = false; | |
if (!empty($value)) { | |
$re = "/^((((\+[\d\-.]{1,5})?[ \-.]?\d{3})|(\+[\d\-.]{1,5})?[ \-.]?\((\d{3}\)))?[ \-.]?\d{3}[ \-.]?\d{4}\s?(e?x?t?\.?\s?\d{1,7})?)?$/i"; | |
if (preg_match($re, $value) === 1) $success = true; | |
} | |
if (!$success) { | |
$validator->addError($key, 'Please enter a valid phone number.'); | |
return false; | |
} else { | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment