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 é, and then it worked seemlessly. But why doesn't the php recognize a simple é in the regexp, but a é entered by the user?
Could you help me please ?
Thank you very much !
Regular expression (eacute)
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Regular expression (eacute)
How about,
Simply convert the entities to their respected character first, then the match should be simple.
Code: Select all
preg_match("#^[\w-']+$#i", html_entity_decode($name));-
helpercenter
- Forum Newbie
- Posts: 5
- Joined: Sat Feb 09, 2008 5:09 pm
Re: Regular expression (eacute)
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!
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)
problem solved. thank you!