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
It works well but is it possible to validate the phone field before the form submission?
I expect the validation like the national/international setting.
Hence my form is required payment and use a [Paypal] button to replace with the [Send] button. The scenario becomes wierd that the users need complete the Paypal process. After then it returns back to the entry form with warning of invalid format of phone number. It causes the users confusion on the payment status.
Please help…
Hello there @brian728
Could you please export this form and share it here with us via a service like Google Drive or Pastebin?
https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export
Keep in mind to duplicate it first and remove any sensitive information like email addresses etc.
Thank you,
Dimitris
Hello @brian728 ,
We haven’t heard from you for several days now, so it looks like you don’t have more questions for us.
Feel free to re-open this ticket if needed.
Kind regards
Kasia
Hello I am joscor and I use forminator..
I have a little issue with the plugin as it does not support 0901 Nigerian number? What can be done?
Most numbers in Nigeria start from 0901 is there a script to validate this?
Hello @ajoscor !
Hope you’re doing well today!
As this is an old topic and the rules for this forum require to create separate tickets, please open a new one instead here: https://ww.wp.xz.cn/support/plugin/forminator/#new-topic-0 and our team will assist you further.
Warm regards,
Pawel