I want to make Pancard validation in wordpress contact form 7 is it possible please help me.
Asked
Active
Viewed 586 times
1 Answers
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;
}
-
if ( 1 !== preg_match ( "/[A-Z]{3}([CHFATBLJGP])[0-9]{4}[A-Z]/ig" , $your_pan) error – Johnson Apr 25 '17 at 11:34
-
there is a missing closing ')' which I have corrected in the code – Aurovrata Apr 25 '17 at 17:05