0

I want to make Pancard validation in wordpress contact form 7 is it possible please help me.

Johnson
  • 5
  • 1
  • 1
  • 5

1 Answers1

0

sure, you can get a regex for the pan-card number validation and then validate the values eitehr in the backend using CF7 filter or on the front-end using javascript to detect pan card field change.

Assuming you have an input text field named your-pancard, something like this should work, but I have not tested it,

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;
}
Community
  • 1
  • 1
Aurovrata
  • 2,000
  • 27
  • 45