Support » Plugin: Contact Form 7 » Required fields radiobuttons and validation

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Hans,

    I’ve implemented this telephone validation code today and it’s working great for me.

    /*
    Validate Telephone and FAX Numbers in Contact Form 7 This is for 11 digit numbers
    */

    function is_number( $result, $tag ) {
    $type = $tag[‘type’];
    $name = $tag[‘name’];

    if ($name == ‘phone’ || $name == ‘fax’) { // Validation applies to these textfield names. Add more with || inbetween
    $stripped = preg_replace( ‘/\D/’, ”, $_POST[$name] );
    $_POST[$name] = $stripped;
    if( strlen( $_POST[$name] ) != 11 ) { // Number string must equal this
    $result[‘valid’] = false;
    $result[‘reason’][$name] = $_POST[$name] = ‘Please enter an 11 digit phone number.’;
    }
    }
    return $result;
    }

    add_filter( ‘wpcf7_validate_text’, ‘is_number’, 11, 2 );
    add_filter( ‘wpcf7_validate_text*’, ‘is_number’, 11, 2 );

    Add it at the end of your themes/functions.php but before the ‘?>’

    Fastest support ever, thanks! I will past the code in the script tomorrow.

    Did you see my second question about the radiobuttons?

    Kind regards, Hans.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Required fields radiobuttons and validation’ is closed to new replies.