Page 1 of 1
Check characters of a variable
Posted: Thu Oct 25, 2007 6:12 pm
by SirChick
Is there a way to check if a variable contains symbols? And then if it does produce an error?
example:
chee'se or ch{}#eese = error
but cheese would be ok.
Posted: Thu Oct 25, 2007 6:13 pm
by feyd
Yes and yes.
Posted: Thu Oct 25, 2007 6:26 pm
by CoderGoblin
Solution would be regular expressions. Precise details not easily given as which characters are allowed a-z, 0-9, öäü ? If using UTF-8 you may also want to look at
Multibyte String Functions
Posted: Thu Oct 25, 2007 6:30 pm
by feyd
At this point, I can only recommend
ctype_alnum().
Posted: Thu Oct 25, 2007 6:42 pm
by Kieran Huggins
wow - I've never even seen those functions before - nice! It would be wicked fast compared to my default regexp instinct.
Posted: Thu Oct 25, 2007 6:47 pm
by CoderGoblin
Glad I'm not the only one who just learnt something
