Created
March 2, 2017 09:47
-
-
Save vdbkw/195faa51b518d8bea64e63876f1e2768 to your computer and use it in GitHub Desktop.
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
/** | |
* NL mobile phone validation | |
Landline: (((0)[1-9]{2}[0-9][-]?[1-9][0-9]{5})|((\\+31|0|0031)[1-9][0-9][-]?[1-9][0-9]{6}))$ | |
Mobile: (((\\+31|0|0031)6){1}[1-9]{1}[0-9]{7})$ | |
set css class phone field to: mobiel | |
*/ | |
add_filter( 'gform_field_validation', 'validate_phone', 10, 4 ); | |
function validate_phone( $result, $value, $form, $field ) { | |
$pattern = '/^(((\\+31|0|0031)6){1}[1-9]{1}[0-9]{7})$/i'; | |
if ( $field->type == 'phone' && ! preg_match( $pattern, $value ) && !(strpos($field->cssClass, 'mobiel') === false) && $result['is_valid'] ) { | |
$result['is_valid'] = false; | |
$result['message'] = empty( $field->errorMessage ) ? 'Dit is geen mobiel nummer.' : $field->errorMessage; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment