【问题标题】:How to make pancard validation in wordpress contact form 7?如何在 wordpress 联系表 7 中进行 pancard 验证?
【发布时间】:2017-04-25 06:38:55
【问题描述】:

我想在 wordpress 联系表 7 中进行 Pancard 验证,是否可以请帮助我。

【问题讨论】:

    标签: wordpress contact-form-7


    【解决方案1】:

    当然,您可以获得regex for the pan-card 号码验证,然后在后端使用CF7 filter 验证值eitehr 或在前端使用javascript 来检测泛卡字段更改。

    假设您有一个名为 your-pancard 的 input 文本字段,这样的东西应该可以工作,但我还没有测试过,

    add_filter( 'wpcf7_validate_text*', 'validate_pan_card', 20, 2 );
    function validate_pan_card( $result, $tag ) {
      $tag = new WPCF7_FormTag( $tag );
      if ( 'your-pancard' == $tag->name ) {
          $your_pan = isset( $_POST['your-pancard'] ) ? trim( $_POST['your-pancard'] ) : '';
          if ( 1 !== preg_match ( "/[A-Z]{3}([CHFATBLJGP])[0-9]{4}[A-Z]/ig" ,  $your_pan) ){
              $result->invalidate( $tag, "PAN Card number is invalid" );
          }
      }
      return $result;
    }
    

    【讨论】:

    • if ( 1 !== preg_match ( "/[A-Z]{3}([CHFATBLJGP])[0-9]{4}[A-Z]/ig" , $your_pan) 错误跨度>
    • 我已在代码中更正了一个缺少的结束 ')'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多