Regular expression (eacute)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
helpercenter
Forum Newbie
Posts: 5
Joined: Sat Feb 09, 2008 5:09 pm

Regular expression (eacute)

Post 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 !
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Regular expression (eacute)

Post 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.
helpercenter
Forum Newbie
Posts: 5
Joined: Sat Feb 09, 2008 5:09 pm

Re: Regular expression (eacute)

Post 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!
helpercenter
Forum Newbie
Posts: 5
Joined: Sat Feb 09, 2008 5:09 pm

Re: Regular expression (eacute)

Post by helpercenter »

problem solved. thank you!
Post Reply