Page 1 of 1

preg_match RegEx

Posted: Tue May 19, 2009 5:51 pm
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

Re: preg_match RegEx

Posted: Tue May 19, 2009 6:29 pm
by requinix
Any particular reason you feel the need to validate a person's name?

Re: preg_match RegEx

Posted: Wed May 20, 2009 7:47 am
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.

Re: preg_match RegEx

Posted: Fri May 29, 2009 4:59 pm
by narolis
I solved my problem, It was caused by the encoding of my Aptana.

thank to you all