【问题标题】:How to validate Indian Mobile number Contact Form 7 in WordPress?如何在 WordPress 中验证印度手机号码联系表 7?
【发布时间】:2021-08-06 09:56:57
【问题描述】:

我想验证印度手机号码。手机号码格式如下:

9775876662、8156652458、7596658556、6655485568

下面的正则表达式:

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 );
}

我想改变模式。请帮忙。

【问题讨论】:

    标签: php regex wordpress contact-form-7


    【解决方案1】:

    你可以使用wpcf7_is_tel过滤钩子。

    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 );
    

    有用的链接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 2016-05-27
      • 2017-03-05
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      相关资源
      最近更新 更多