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?
Checking for non-letter characters?
Moderator: General Moderators
Re: Checking for non-letter characters?
Sometimes a problem becomes easier if it you think about the inverse.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?
(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.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
viewtopic.php?t=45203 may be of interest to both of you.