Page 1 of 1
Checking for non-letter characters?
Posted: Tue Oct 31, 2006 9:32 am
by Citizen
Cheers,
I searched php.net and phpdn forums for an answer for this but couldnt find it.
I want to check to make sure that users dont have any characters that arent letters or numbers like symbols and stuff.
How can this be accomplished?
Re: Checking for non-letter characters?
Posted: Tue Oct 31, 2006 10:02 am
by timvw
Citizen wrote:Cheers,
I searched php.net and phpdn forums for an answer for this but couldnt find it.
I want to check to make sure that users dont have any characters that arent letters or numbers like symbols and stuff.
How can this be accomplished?
Sometimes a problem becomes easier if it you think about the inverse.
(1) The inverse to your problem is verifying if a string only contains letters or digits
(2) A possible solution for (1) is the following is to check if the string preg_matches #^\w+$#
(3) Back to your original problem, if there is a string that does not preg_match the expression in (2) there is invalid data
(4) Time for improvement: \W matches everything that is not a a letter or digit. So if any of the input strings matches \W there is a problem.
Posted: Tue Oct 31, 2006 5:44 pm
by feyd
viewtopic.php?t=45203 may be of interest to both of you.