Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3347372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:24:50+00:00 2026-05-18T01:24:50+00:00

I am using preg_match function to filter unwanted characters from a textarea form in

  • 0

I am using preg_match function to filter unwanted characters from a textarea form in 2 PHP scripts I made, but in one of them seems not to work.

Here’s the script with the problem:

<?php
    //Database connection, etc......

    mysql_select_db("etc", $con);
    $errmsg = '';
    $chido = $_POST['chido'];
    $gacho = $_POST['gacho'];
    $maestroid = $_POST['maestroid'];
    $comentario = $_POST['comment'];
    $voto = $_POST['voto'];

    if($_POST['enviado']==1) {
        if (preg_match ('/[^a-zA-Z áéíóúüñÁÉÍÓÚÜÑ]/i', $comentario))
            $errmsg = 1;
        if($errmsg == '') {
            //here's some queries, etc
        }
    }

    if($errmsg == 1)
        echo "ERROR: You inserted invalid characters...";
?>

So as you can see the preg_match just filter unwanted chracters like !”#$%&/() etc..

But every time I type a special character like ‘ñ’ or ‘á’ it triggers the error code.

I have this very similar script that works perfectly with the same preg_match and filters just the unwanted characters:

//Database connection, etc..
mysql_select_db("etc", $con);
$errmsg = '';

if ($_POST['enviado']==1) {
     $nombre = $_POST['nombre'];
     $apodo = $_POST['apodo'];
     $mat1 = $_POST['mat1'];
     $mat2 = $_POST['mat2'];
     $mat3 = $_POST['mat3'];

     if (preg_match ('/[^a-zA-Z áéíóúüñÁÉÍÓÚÜÑ]/i', $nombre))
         $errmsg = 1;


     if($errmsg == '') {
         //more queries after validation
     }
}

if($errmsg == 1)
    echo "ERROR: etc......."
?>

So the question is, what am I doing wrong in the first script??

I tried everything but always fails and shows the error.

Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:24:51+00:00Added an answer on May 18, 2026 at 1:24 am

    This might help: http://www.phpwact.org/php/i18n/charsets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i use this pattern '/(\{(\w+)\}(.*))?\{%(\w+)%\}((.*)\{\/(\w+)\})?/i' to extract tags from a template using preg_match function.
I need to call a static function from an object using the Singleton design,
I am using preg_match() function only to allow specific charachters to accept. It is
return preg_match('/^(\d*\p{Arabic}+*)$/iu', $str); I'm using the function above in order to match string such
I am using this PHP function to grab all <img> tags within any given
Using ASP.NET MVC there are situations (such as form submission) that may require a
I have a form with jQuery.validate. It checks if typed email is correct using
I've finally got this PHP email script working (didn't work on localhost…), but my
Is it possible to filter out only the shortcode from the post and then
So I have such php function I want to translate to C++: protected function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.