views:

45

answers:

2

Hi,

I search the internet but I couldn't find a proper answer so I try this way.

I use this code to validate UTF-8 input. I want to allow printable chars and some specified special chars.

$pattern = '/[^\w\.\-\s\,\&\!\?\(\)\+\_\:\;]+$/u';
$status = @preg_match($pattern, $value);
if (($status === false) || ($status > 0)) {
    return false;
}

Everything works fine, EXCEPT the input string has at the end a non ascii char (eg. é). Then my validation fails, but it should not. I know it might be a silly mistake, but thanks in advance for every proposal.

best regards

+2  A: 

Try Unicode character properties:

/[^\p{L}.\-\s,&!?()+_:;]+$/u

Here \p{L} represents any Unicode character that is categorized as a letter.

Gumbo
the following script works now: '/[^\p{L}\p{Nd}.\-\s,]+$/u' adding the \p{Nd} for the digits, thanks for your answer ;)
max
+1  A: 

use \pL to match any letter character

knittl