Hello @brian728 !
I trust you’re doing well!
We have a script for validating the phone numbers in a more detailed way. I’ve already prepared it for you to match only the rules you’ve provided:
<?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 ) {
if($form_id != 429) {
return $submit_errors;
}
$valid = false;
foreach( $field_data_array as $val ) {
if( $val['name'] == 'phone-1' ) {
$phone = $val['value'];
$pattern = '/^[23569][0-9]{7}$/';
if( preg_match( $pattern, $phone ) ){
$valid = true;
}
break;
}
}
if( ! $valid ) {
$submit_errors[]['phone-1'] = 'Please use the correct format!';
}
return $submit_errors;
}
To install the script:
1. Copy the code to a file with any name and .php extension
2. Edit $form_id != 429 to match the ID of your form (ID is in the shortcode or in the form’s edit screen address)
3. Save and upload the file to wp-content/mu-plugins (create the directory if it doesn’t exist yet)
4. Set the phone field to Validation = None
5. Test ??
On my test site it worked well and it only allowed numbers such as:
25422424
35422424
55422424
65422424
95422424
But not:
45422424
3542242454
354224
Warm regards,
Pawel