Page 1 of 1

Regular expression (eacute)

Posted: Sat Feb 09, 2008 5:17 pm
by helpercenter
Hi!

I have the following problem :

I want to test following strings with a regular expression (it is for testing names) :

O'Connor
Anne-Marie
Frédéric
Geneviève
...

and names including à, ä, ...

They should NOT contain numbers, *,%,&,/,. ...

I tried already this expression (without success) :

$regex = "/^([a-zA-Z]+)|(eacute\x3B)$/";

In fact, I think that following is correct :^[a-zA-Z-\é]+$

However, it does not work if I try to send a name via PHP to the validation file. It seems for instance that the é is not recognized as é, but as another letter. I have already tried to enter &eacute, and then it worked seemlessly. But why doesn't the php recognize a simple é in the regexp, but a &eacute entered by the user?

Could you help me please ?

Thank you very much !

Re: Regular expression (eacute)

Posted: Sat Feb 09, 2008 5:34 pm
by John Cartwright
How about,

Code: Select all

preg_match("#^[\w-']+$#i", html_entity_decode($name));
Simply convert the entities to their respected character first, then the match should be simple.

Re: Regular expression (eacute)

Posted: Sun Feb 10, 2008 3:12 am
by helpercenter
Hi,

Thank you for your reply!

I have tested it now:

if(preg_match("/^[\w-']+$/i", html_entity_decode($yourname)))
{
echo " ok";
}
else
{
echo " error";
}

but if I enter "test" - result "ok"
if I enter "test123" - result "ok" <-- but it should be error because there are numbers
if I enter testé, it gives me as a result "error" <-- but it should be ok, because it should accept é!

How to do so?

Thank you very much! This forum is so great!

Re: Regular expression (eacute)

Posted: Sun Feb 10, 2008 11:57 am
by helpercenter
problem solved. thank you!