Check out our newest developed Magento 2 Customer Discount More Info

Importance of Phone Validation Code in WordPress Contact Form

It is very difficult task to develop websites with all latest features. Latest features containing websites are helpful in attracting huge number of visitors as it is easy to access. But there are some challenges that have to face by webmaster while creating websites. It is must for you to appoint well-experienced professional of PSD to WordPress conversion service, if you want to create high quality website with appropriate codes. Make sure that professionals are creating codes, which are compatible with all the browsers. Aside to this feature, one can have to consider that website has authenticated with emails and phone numbers.

As we all have an idea that emails and phone numbers are must for running business successfully. If you want to confirm business deal then you have to require emails and phone numbers for contacting clients. Phone number will helpful to identify that client is lawful or not. Email validation and phone validation are used for such case also. Various codes are available that are very helpful for phone validation and email validation.

With the help of such codes, one can easily run and manage their websites along with maintaining data quality of their addresses. This type of codes is helpful for identifying client’s name, addresses, email validation and many other things as phone number is obtainable through such codes. Client cannot able to insert characters in place of numbers. So, there is no chance of invalid phone number. With such type of code, one can improve the overall quality of their data.

One of the great advantages of this coding is it can helpful to raise the consistency of the contact data and also maintain quality of data. So, if you want to improve abilities of your website and increase your business by making proper contact with clients then simply add phone validation in WordPress contact form by going through some steps. Below you will find appropriate coding that you just have to copy and paste at appropriate place:

Steps to Add Phone Validation in wordpress contact form:

Open the “contact-form-7″ folder located in your wp-contents/plugins folder.

STEP 1. Open “contact-form-7/modules/text.php”:

insert this code:

[code]wpcf7_add_shortcode( ‘number’, ‘wpcf7_text_shortcode_handler’, true );

wpcf7_add_shortcode( ‘number*’, ‘wpcf7_text_shortcode_handler’, true );[/code]

after this code:

[code]wpcf7_add_shortcode( ’email*’, ‘wpcf7_text_shortcode_handler’, true );[/code]

insert this code:

[code]if ( ‘number’ == $type || ‘number*’ == $type )

$class_att .= ‘ wpcf7-validates-as-digit’;[/code]

after this code:

[code]if ( ‘text*’ == $type || ’email*’ == $type )

$class_att .= ‘ wpcf7-validates-as-required’;[/code]

insert this code:

[code]add_filter( ‘wpcf7_validate_number’, ‘wpcf7_text_validation_filter’, 10, 2 );

add_filter( ‘wpcf7_validate_number*’, ‘wpcf7_text_validation_filter’, 10, 2 );[/code]

after this code:

[code]add_filter( ‘wpcf7_validate_email’, ‘wpcf7_text_validation_filter’, 10, 2 );[/code]

insert this code:

[code]if ( ‘number’ == $type || ‘number*’ == $type ) {

if ( ‘number*’ == $type && ” == $_POST[$name] ) {

$result[‘valid’] = false;

$result[‘reason’][$name] = wpcf7_get_message( ‘invalid_required’ );

} elseif ( ” != $_POST[$name] && ! is_validNumber( $_POST[$name] ) ) {

$result[‘valid’] = false;

$result[‘reason’][$name] = wpcf7_get_message( ‘invalid_number’ );



after this code:

[code]if ( ’email’ == $type || ’email*’ == $type ) {

if ( ’email*’ == $type && ” == $_POST[$name] ) {

$result[‘valid’] = false;

$result[‘reason’][$name] = wpcf7_get_message( ‘invalid_required’ );

} elseif ( ” != $_POST[$name] && ! is_email( $_POST[$name] ) ) {

$result[‘valid’] = false;

$result[‘reason’][$name] = wpcf7_get_message( ‘invalid_email’ );



STEP 2. Open “contact-form-7/modules/text.php”:

insert this code in Function wpcf7_add_tag_generator_text_and_email():

[code]wpcf7_add_tag_generator( ‘number’, __( ‘Number field’, ‘wpcf7’ ),

‘wpcf7-tg-pane-number’, ‘wpcf7_tg_pane_number’ );

after this code:

wpcf7_add_tag_generator( ’email’, __( ‘Email field’, ‘wpcf7’ ),

‘wpcf7-tg-pane-email’, ‘wpcf7_tg_pane_email’ );

insert new function:

function wpcf7_tg_pane_number( &$contact_form ) {

wpcf7_tg_pane_text_and_email( ‘number’ );


after this code:

[code]function wpcf7_tg_pane_email( &$contact_form ) {

wpcf7_tg_pane_text_and_email( ’email’ );


replace these lines:

[code]function wpcf7_tg_pane_text_and_email( $type = ‘text’) {

if ( ’email’ != $type )

$type = ‘text’;[/code]

STEP 3. Open “contact-form-7/include/function.php”:

insert this code:

[code]’invalid_number’ => array(

‘description’ => __( “There is a field that sender is needed to fill in with numbers”, ‘wpcf7′ ),

‘default’ => __( ‘Please fill the required field with numbers.’, ‘wpcf7′ )


after this code:

[code]’invalid_required’ => array(

‘description’ => __( “There is a field that sender is needed to fill in”, ‘wpcf7′ ),

‘default’ => __( ‘Please fill the required field.’, ‘wpcf7′ )


STEP 4. Open “contact-form-7/include/function.php”:

[code]function is_validNumber($chkNum) {

$regexp = ‘/^[0-9+-)(ds]{7,}$/’;

if(preg_match($regexp, $chkNum))

return true;


return false;


The following two tabs change content below.
Harshal Shah is CEO & Founder of Xhtmljunkies, Located in Gujarat, India, XHTML Junkies is one of the best companies that offer unique eCommerce solutions by the virtue of its dedicated professionals. Our professionals are extremely proficient in offering development services pertaining to eCommerce. You can find Harshal on and Twitter.