Topic: PHP Regex help please!!! Pages that link to <a href="https://ozoneasylum.com/backlink?for=28269" title="Pages that link to Topic: PHP Regex help please!!!" rel="nofollow" >Topic: PHP Regex help please!!!\

 
Author Thread
H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

IP logged posted posted 07-29-2006 03:55 Edit Quote

Arrgg this is driving me mad...

I want to verify input allowing alpha chars and single quotes.

preg_match("/[^ A-Za-z-']/", $inputString)


I can get it to work except for the single char!!! ive tried escaping it and all, what am i doing wrong?


Please help!

divinechaos
Bipolar (III) Inmate

From:
Insane since: Dec 2001

IP logged posted posted 07-29-2006 04:06 Edit Quote

Try this:

code:
preg_match("/^[A-Za-z\']+$/", $string);



Here's a quick breakdown:
"^" is the beginning of the string
"[]" is a character range (e.g. A-Z, a-z and ')
"\'" is an escaped single-quote
"+" means it must contain at least 1 character
"$" is the end of the string


Worked with very brief testing.

Regards,
DC

(Edited by divinechaos on 07-29-2006 04:08)

H][RO
Paranoid (IV) Inmate

From: Australia
Insane since: Oct 2002

IP logged posted posted 07-29-2006 04:28 Edit Quote

Thanks looks good.. funnily enough the problem was elsewhere though - i was of course escaping the input for the sql string before verifying the input. So instead of matching ' it was trying to match \' . Oops!



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu