As we all know that for running business successfully this kind of ideas like emails and phone numbers are must useful. For confirm the business deal then you have to need emails and phone numbers of clients for contact. To identify that client is lawful or not phone number will helpful. In such case email validation and phone validation are used. In that various codes are available that are helpful for phone validation and email validation.
One can easily maintaining data quality of their addresses with the help of such codes and to ran and manage their websites. This type of codes are very halpful for identifying clienl's details alike name, addresses, email validation and many other things as phone number obtainable such codes. Client cannot insert the characters in place of numbers. So, there is no chance of invalid phone number. One can improve the overall quality of their data with such type of code.
To raise the consistency of the client contact data and also maintain quality of the data it is one of the great advantages of coding and it is more helpful. For improveing the abilities of your website and increase your business by proper contact details of clients and 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:
1 wpcf7_add_shortcode( 'number', 'wpcf7_text_shortcode_handler', true );
2
3 wpcf7_add_shortcode( 'number*', 'wpcf7_text_shortcode_handler', true );
after this code:
1 wpcf7_add_shortcode( 'email*', 'wpcf7_text_shortcode_handler', true );
insert this code:
1 if ( 'number' == $type || 'number*' == $type )
2
3 $class_att .= ' wpcf7-validates-as-digit';
after this code:
1 if ( 'text*' == $type || 'email*' == $type )
2
3 $class_att .= ' wpcf7-validates-as-required';
insert this code:
1 add_filter( 'wpcf7_validate_number', 'wpcf7_text_validation_filter', 10, 2 );
2
3 add_filter( 'wpcf7_validate_number*', 'wpcf7_text_validation_filter', 10, 2 );
after this code:
1 add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
insert this code:
01 if ( 'number' == $type || 'number*' == $type ) {
02
03 if ( 'number*' == $type && '' == $_POST[$name] ) {
04
05 $result['valid'] = false;
06
07 $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
08
09 } elseif ( '' != $_POST[$name] && ! is_validNumber( $_POST[$name] ) ) {
10
11 $result['valid'] = false;
12
13 $result['reason'][$name] = wpcf7_get_message( 'invalid_number' );
14
15 }
16
17 }
after this code:
01 if ( 'email' == $type || 'email*' == $type ) {
02
03 if ( 'email*' == $type && '' == $_POST[$name] ) {
04
05 $result['valid'] = false;
06
07 $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
08
09 } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
10
11 $result['valid'] = false;
12
13 $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
14
15 }
16
17 }
STEP 2. Open "contact-form-7/modules/text.php":
insert this code in Function wpcf7_add_tag_generator_text_and_email():
01 wpcf7_add_tag_generator( 'number', __( 'Number field', 'wpcf7' ),
02
03 'wpcf7-tg-pane-number', 'wpcf7_tg_pane_number' );
04
05 after this code:
06
07 wpcf7_add_tag_generator( 'email', __( 'Email field', 'wpcf7' ),
08
09 'wpcf7-tg-pane-email', 'wpcf7_tg_pane_email' );
10
11 insert new function:
12
13 function wpcf7_tg_pane_number( &$contact_form ) {
14
15 wpcf7_tg_pane_text_and_email( 'number' );
16
17 }
after this code:
1 function wpcf7_tg_pane_email( &$contact_form ) {
2
3 wpcf7_tg_pane_text_and_email( 'email' );
4
5 }
replace these lines:
1 function wpcf7_tg_pane_text_and_email( $type = 'text') {
2
3 if ( 'email' != $type )
4
5 $type = 'text';
STEP 3. Open "contact-form-7/include/function.php":
insert this code:
1 'invalid_number' => array(
2
3 'description' => __( “There is a field that sender is needed to fill in with numbers”, 'wpcf7′ ),
4
5 'default' => __( 'Please fill the required field with numbers.', 'wpcf7′ )
6
7 )
after this code:
1 'invalid_required' => array(
2
3 'description' => __( “There is a field that sender is needed to fill in”, 'wpcf7′ ),
4
5 'default' => __( 'Please fill the required field.', 'wpcf7′ )
6
7 ),
STEP 4. Open "contact-form-7/include/function.php":
01 function is_validNumber($chkNum) {
02
03 $regexp = '/^[0-9\+\-\)\(\d\s]{7,}$/';
04
05 if(preg_match($regexp, $chkNum))
06
07 return true;
08
09 else
10
11 return false;
12
13 }