Page 1 of 1
Allowing ' in full name
Posted: Sat Jun 07, 2008 8:00 am
by LonelyProgrammer
Here's a regex I modified to allow ' in full name (well, really exotic names)
However, it seems not to be failing, and the return is \'.
Is my regex wrong, or is magic quotes the source of my woe?
Re: Allowing ' in full name
Posted: Sat Jun 07, 2008 10:39 am
by GeertDD
Escape the quote inside the character class, otherwise it will result in a PHP parse error.
Re: Allowing ' in full name
Posted: Sun Jun 08, 2008 9:17 am
by LonelyProgrammer
$pattern = '#^[a-z\s\.\-\']+$#i'
I swore I type this regex in the first message. I did escape the '
Re: Allowing ' in full name
Posted: Sun Jun 08, 2008 2:00 pm
by prometheuzz
LonelyProgrammer wrote:$pattern = '#^[a-z\s\.\-\']+$#i'
I swore I type this regex in the first message. I did escape the '
Okay, but is there still a problem then? If so, can you post a string that is not matched while you think it should match?
Just a side note: you don't need to escape the . (dot) inside a character class and if you place the - (hyphen) at the start or at the end of the character class, you don't need to escape that either:
$pattern = '#^[a-z\s.\'-]+$#i';
Re: Allowing ' in full name
Posted: Mon Jun 09, 2008 12:29 pm
by LonelyProgrammer
Yes, ' are not being accepted in the text field, and it is being displayed as \' in the input box.
Re: Allowing ' in full name
Posted: Mon Jun 09, 2008 4:03 pm
by prometheuzz
LonelyProgrammer wrote:Yes, ' are not being accepted in the text field, and it is being displayed as \' in the input box.
I presume the "yes" is "yes there is still a problem". Since you didn't quote anyone, I am not sure about it. If this is correct, then again: please post the input that should be matched and the regex that is responsible for the "not matching" of that input string.
Re: Allowing ' in full name
Posted: Wed Jun 11, 2008 1:07 pm
by LonelyProgrammer
prometheuzz wrote:LonelyProgrammer wrote:Yes, ' are not being accepted in the text field, and it is being displayed as \' in the input box.
I presume the "yes" is "yes there is still a problem". Since you didn't quote anyone, I am not sure about it. If this is correct, then again: please post the input that should be matched and the regex that is responsible for the "not matching" of that input string.
Hi,
Sorry for not making my post clear.
Example string to be matched: Abdul-'Adl
Regex used: $pattern = '#^[a-z\s.\'-]+$#i';
And I got the quote escaped back in the input text; So I am wondering if it's a magic quote issue after all
Re: Allowing ' in full name
Posted: Wed Jun 11, 2008 1:27 pm
by GeertDD
Right, this is magic quotes madness. Nothing to do with regex.
http://www.sitepoint.com/blogs/2005/03/ ... headaches/