Created
October 24, 2018 13:23
-
-
Save bappi-d-great/7f632de2fd83c02aab21e880d8a8fbc2 to your computer and use it in GitHub Desktop.
WPMU DEV Forminator phone number validation
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 | |
// Assuming one phone field in a form | |
add_filter( 'forminator_custom_form_submit_errors', 'check_form_data', 99, 3 ); | |
function check_form_data( $submit_errors, $form_id, $field_data_array ) { | |
$valid = false; | |
foreach( $field_data_array as $val ) { | |
if( $val['name'] == 'phone-1' ) { | |
$phone = $val['value']; | |
$pattern = '/^(([+][6][5])\s(\d{8}))?$/'; | |
if( preg_match( $pattern, $phone ) ){ | |
$valid = true; | |
} | |
break; | |
} | |
} | |
if( ! $valid ) { | |
$submit_errors[]['phone-1'] = 'Please use the correct format!'; | |
} | |
return $submit_errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"phone-1" its always the name of the phone fields?