URL Validation for message box :: WordPress

0
489

Hello readers,

If you are using wordpress website and spamming occurs too much and in spam mails their are URLs then you should have to validate that message box and prevent user or spammer to add any type of URL in message box i.e. textarea or any input. Add below code in your “functions.php” of activated theme

add_filter( 'wpcf7_validate_textarea', 'alphanumeric_validation_filter', 2000, 2 );

function alphanumeric_validation_filter( $result, $your_message )
{
$your_message = new WPCF7_Shortcode( $your_message );
if ( 'your-message' == $your_message->your-message )
{
$name_of_the_input = isset( $_POST['your-message'] ) ? trim( $_POST['your-message'] ) : '';
if ( !preg_match('/^[a-zA-Z. ?0-9-,]+$/',$name_of_the_input) )
{
$result->invalidate( $your_message, "Allowed characters only" );
}
}
return $result;
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here