Just Start Typing Text and Press Enter

alt text
PANKAJ SINGH
Web Designer & Developer

DRINK A COFFEE WITH ME TODAY

Loading...
Message Snet
Error!

Blog posts

Menu
Close
Apr 18, 2016

CONTACT FORM 7 CUSTOM VALIDATION FOR CHARACTERS ONLY

0 Comment | By
CONTACT FORM 7 CUSTOM VALIDATION

function my2_wpcf7_validate_text( $result, $tag ) {

 

    $type = $tag[‘type’];

    $name = $tag[‘name’];

    $value = $_POST[$name];

 

    if ( strpos( $name, ‘org’ ) !== false ){

    $regex = ‘/^[A-Za-z]+$/’;

    $Valid = preg_match($regex,  $value, $matches );

            if ( $Valid > 0 ) {

            }

            else {

                $result->invalidate( $tag, wpcf7_get_message( ‘invalid_org’ ) );

            }

        }

  

         return $result;

}

 

add_filter( ‘wpcf7_validate_text*’, ‘my2_wpcf7_validate_text’ , 12, 2 );

 

add_filter( ‘wpcf7_messages’, ‘my2wpcf7_text_messages’ );

function my2wpcf7_text_messages( $messages ) {

    return array_merge( $messages, array(

                                         ‘invalid_org’ => array(

                                                                 ‘description’ => __( “Organization name is invalid”, ‘contact-form-7’ ),

                                                                 ‘default’ => __( ‘Organization name is invalid.’, ‘contact-form-7’ )

                                                                 )));

                                        

}

Leave A Comment

Author Details

My name is Pankaj Singh and I am a web designer and developer with over 3+ years of professional experience in the design industry, currently living in New Delhi, India. I have a Master of Computer Application from GGSIPU University, and my primary focus and inspiration for studies is Web Development.

Share Post