Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created October 24, 2018 13:23
Show Gist options
  • Save bappi-d-great/7f632de2fd83c02aab21e880d8a8fbc2 to your computer and use it in GitHub Desktop.
Save bappi-d-great/7f632de2fd83c02aab21e880d8a8fbc2 to your computer and use it in GitHub Desktop.
WPMU DEV Forminator phone number validation
<?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;
}
@yonifre
Copy link

yonifre commented Dec 19, 2023

"phone-1" its always the name of the phone fields?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment