如何在 wordpress 联系表 7 中进行 pancard 验证?

How to make pancard validation in wordpress contact form 7?

我想在 wordpress contact form 7 中进行 Pancard 验证是否可行请帮助我。

当然,你可以得到一个 number validation and then validate the values eitehr in the backend using CF7 filter或者在前端使用javascript来检测pan card字段的变化。

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

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