Created
October 30, 2015 07:12
-
-
Save sepiariver/924460da645bc35a6e6a 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