Contact form 7: Prevent input html tag in text field

How to create validation in contact form 7 to prevent user input HTML tag like

...

or , also to prevent scripts like $(dummy){}.

I create validation to prevent URL and non Latin characters, how I can create for HTML tag or scripts?

Here my code:

    function custom_text_validation_filter($result, $tag) {  
$type = $tag['type'];
$name = $tag['name'];
if($name == 'your-subject') {
$value = $_POST[$name];
        $nourl_pattern = '(http|https|href)';
        $latin = /^[a-zA-ZàèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇßØøÅåÆæœ\s\d.('\£$%!*()}{@#~|=_+^?\/\\;:,,.)]+$/;
if(preg_match($nourl_pattern,$value)){

    $result-invalidate( $tag, Subject cannot contain website addresses. );
                }
                
else if(!preg_match($latin,$value)){

    $result-invalidate( $tag, Subject cannot contain non-latin word. );
                }
}
return $result;
}
add_filter('wpcf7_validate_text','custom_text_validation_filter', 10, 2);
add_filter('wpcf7_validate_text*', 'custom_text_validation_filter', 10, 2);

Topic validation regex plugin-contact-form-7 contact custom-field Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.