• Hi,
    Is there any way contact form 7 can validate(accept) the email field only Business Email.. (not gmail.yahoo, and so on)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter shriram1994

    (@shriram1994)

    My question is not about confirm email.
    it is validation of business email

    (i.e) if i entered [email protected] (or)[email protected]
    It will throw error message “Please enter business emails”

    Not only gmail and yahoo it was just an example

    So the valid emails are [email protected]

    Thread Starter shriram1994

    (@shriram1994)

    I fount one solution from internet

    // Add custom validation for CF7 form fields
    function is_company_email($email){ // Check against list of common public email providers & return true if the email provided *doesn’t* match one of them
    if(
    preg_match(‘/@gmail.com/i’, $email) ||
    preg_match(‘/@hotmail.com/i’, $email) ||
    preg_match(‘/@live.com/i’, $email) ||
    preg_match(‘/@msn.com/i’, $email) ||
    preg_match(‘/@aol.com/i’, $email) ||
    preg_match(‘/@yahoo.com/i’, $email) ||
    preg_match(‘/@inbox.com/i’, $email) ||
    preg_match(‘/@gmx.com/i’, $email) ||
    preg_match(‘/@me.com/i’, $email)
    ){
    return false; // It’s a publicly available email address
    }else{
    return true; // It’s probably a company email address
    }
    }

    function custom_email_validation_filter($result, $tag) {

    $tag = new WPCF7_Shortcode( $tag );

    if ( ‘company-email’ == $tag->name ) {

    $the_value = isset( $_POST[‘company-email’] ) ? trim( $_POST[‘company-email’] ) : ”;

    if(!is_company_email($the_value)){
    $result->invalidate( $tag, “Please Enter a valid Business Email ID” );
    }
    }
    return $result;
    }

    add_filter( ‘wpcf7_validate_email’, ‘custom_email_validation_filter’, 10, 2 );
    add_filter( ‘wpcf7_validate_email*’, ‘custom_email_validation_filter’, 10, 2 );

    is this correct?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to validation business email in Contact Form 7?’ is closed to new replies.