Collecting accurate contact details from users is essential for effective communication. One common issue faced by businesses is users submitting incorrect or incomplete phone numbers. To tackle this, here’s how you can add a simple yet effective 10-digit phone number validation to your Elementor forms using PHP.
Why Validate Phone Numbers?
Validating phone numbers ensures that your database contains reliable data. It helps in:
- Maintaining data accuracy.
- Improving customer service by having valid contact information.
- Preventing fake or incorrect data entries.
PHP Code for Phone Number Validation
Below is an easy-to-use PHP snippet that integrates seamlessly with Elementor forms:
<?php
function validate_phone_number( $field, $record, $ajax_handler ) {
if ( ! empty( $field['value'] ) && strlen( $field['value'] ) !== 10 ) {
$ajax_handler->add_error( $field['id'], 'Phone number must be exactly 10 digits long.' );
}
}
add_action( 'elementor_pro/forms/validation/tel', 'validate_phone_number', 10, 3 );
How Does This Work?
- The function checks if the entered phone number is exactly 10 digits.
- If it’s not, an error message “Phone number must be exactly 10 digits long.” is displayed.
- Users must correct their input before form submission is accepted.
Implementing the Validation
- Copy the provided PHP code.
- Install and activate a code snippet plugin (such as “Code Snippets”) on your WordPress website.
- Create a new snippet, paste the PHP code, and activate it.
- Save your changes and test the Elementor form to ensure the validation works correctly.
By following these simple steps, you’ll enhance your data collection process, ensuring your company database remains accurate and useful for customer interactions.


