• davidami

    (@davidami)


    Hi,

    i would like to validate a text tag in contact form 7, to validate an italian car plate, this is my RegExp in JavaScript:

     <script>
    		
    		function targaCheck(){
    var targaRExp = /^(([a-zA-Z]{2}\d{3}[a-zA-Z]{2})|(([a-zA-Z]{2}|roma)(\d{5}|\d{6})))$/i;
    var targa = document.getElementById("targa").value;
    
    		if( targaRExp.test(targa) ) {
       alert("Correct");
    }else {
       alert("Incorrect");
    }
    		}
    		</script> 

    To validate the contact form 7 i have to use “add_filter” in function.php of my WP site, but when i insert my code it doesn’t work. (this is an example of code)
    https://contactform7.com/2015/03/28/custom-validation/

    add_filter( 'wpcf7_validate_email*', 'custom_email_confirmation_validation_filter', 20, 2 );
     
    function custom_email_confirmation_validation_filter( $result, $tag ) {
        $tag = new WPCF7_FormTag( $tag );
     
        if ( 'your-email-confirm' == $tag->name ) {
            $your_email = isset( $_POST['your-email'] ) ? trim( $_POST['your-email'] ) : '';
            $your_email_confirm = isset( $_POST['your-email-confirm'] ) ? trim( $_POST['your-email-confirm'] ) : '';
     
            if ( $your_email != $your_email_confirm ) {
                $result->invalidate( $tag, "Are you sure this is the correct address?" );
            }
        }
     
        return $result;
    }

    how can i do?

    Please help me

    Thanks!

  • The topic ‘Custom Validation form’ is closed to new replies.