1

I want to validate Indian mobile numbers. The format of the mobile number is as follows:

9775876662, 8156652458, 7596658556, 6655485568

The regEx that is below:

function wpcf7_is_tel( $tel ){
    $pattern = '%^[+]?' // + sign
        . '(?:\([0-9]+\)|[0-9]+)' // (1234) or 1234
        . '(?:[/ -]*' // delimiter
        . '(?:\([0-9]+\)|[0-9]+)' // (1234) or 1234
        . ')*$%';
    $result = preg_match( $pattern, trim( $tel ) );
    return apply_filters( 'wpcf7_is_tel', $result, $tel );
}

I want to change the pattern. Please help.

Bhautik
  • 11,125
  • 3
  • 16
  • 38
Ksu Thakur
  • 11
  • 1

1 Answers1

0

You can use wpcf7_is_tel filter hook.

function valid_indian_mobile_number( $result, $tel ) { 
    $result = preg_match( '/^[6-9][0-9]{9}$/', $tel );
    return $result; 
}
add_filter( 'wpcf7_is_tel', 'valid_indian_mobile_number', 10, 2 );

USEFUL LINKS

Bhautik
  • 11,125
  • 3
  • 16
  • 38