Uncategorized – Ganga https://gangaramdas.com Learn how to Build Awesome Websites & Create a Web Design Business Fri, 24 Oct 2025 08:31:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://gangaramdas.com/wp-content/uploads/2020/06/cropped-small-favio-32x32.png Uncategorized – Ganga https://gangaramdas.com 32 32 How to Add Phone Number Validation in WPForms https://gangaramdas.com/how-to-add-phone-number-validation-in-wpforms/ https://gangaramdas.com/how-to-add-phone-number-validation-in-wpforms/#respond Fri, 24 Oct 2025 08:31:28 +0000 https://gangaramdas.com/?p=218492 This blog is about how to validate phone number fields in WPForms.
By adding this method, you can make sure users enter only valid phone numbers such as 10-digit formats.
It helps in maintaining correct data for leads or contact forms.

 

/**
* Add phone number validation in WPForms
*/
function wpforms_custom_phone_validation( $field_id, $field_submit, $form_data ) {

// Optional: Change field ID if needed (1 = Phone field ID)
if ( $field_id == ‘1’ && !empty( $field_submit ) ) {

// Allow only 10 digit numbers
if ( !preg_match( ‘/^[0-9]{10}$/’, $field_submit ) ) {
wpforms()->process->errors[ $form_data[‘id’] ][ $field_id ] = esc_html__( ‘Please enter a valid 10-digit phone number.’, ‘wpforms’ );
}
}
}
add_action( ‘wpforms_process_validate’, ‘wpforms_custom_phone_validation’, 10, 3 );

]]>
https://gangaramdas.com/how-to-add-phone-number-validation-in-wpforms/feed/ 0