preg_match RegEx

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
narolis
Forum Newbie
Posts: 9
Joined: Tue Feb 10, 2009 4:36 pm

preg_match RegEx

Post by narolis »

Hi,

I'm trying to make validation for my form and I have some problems with my RegEx.

I have for example a RexEx to validate the name and firstname.

Code: Select all

 
'/^[A-ZÉÏÎÈÇ A-Za-z \-ZÉÏÎÈÇéïîèç]+([ ][A-ZÉÏÎÈÇ][a-zéïîèç]*)?[a-z \-éïîèç]*[a-zéïîèç]$/'
 
The problem is that it don't work when I'm using post values

Code: Select all

 
preg_match('/^[A-ZÉÏÎÈÇ A-Za-z \-ZÉÏÎÈÇéïîèç]+([ ][A-ZÉÏÎÈÇ][a-zéïîèç]*)?[a-z \-éïîèç]*[a-zéïîèç]$/', $_POST['name']);
 
 
$_POST['name'] = 'Étienne';
 
But when I hardcode a value it work

Code: Select all

 
preg_match('/^[A-ZÉÏÎÈÇ A-Za-z \-ZÉÏÎÈÇéïîèç]+([ ][A-ZÉÏÎÈÇ][a-zéïîèç]*)?[a-z \-éïîèç]*[a-zéïîèç]$/', 'Étienne');
 
Both ways use the same RegEx why it don't work with $_POST but it do with hardcoded value. I need to use the $_POST.

Thank you
Last edited by Benjamin on Tue May 19, 2009 8:25 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: preg_match RegEx

Post by requinix »

Any particular reason you feel the need to validate a person's name?
narolis
Forum Newbie
Posts: 9
Joined: Tue Feb 10, 2009 4:36 pm

Re: preg_match RegEx

Post by narolis »

I validate all my form fields.

I have RegEx for name, city, region, country, email, postal code, url, telephone number,...

They all work except he ones using accent characters when using the $_POST but with hardcoded value it work.
narolis
Forum Newbie
Posts: 9
Joined: Tue Feb 10, 2009 4:36 pm

Re: preg_match RegEx

Post by narolis »

I solved my problem, It was caused by the encoding of my Aptana.

thank to you all
Post Reply