how to test string whether it contains special characters
Collapse
X
-
hsriat, I think the OP is long gone, this is a very old post that has been dug up and put at the top of the list :(
Amen.Originally posted by MarkusFurthermore, that loop is completely unnecessary. Using preg_match() you can do that in 1 line of code.Comment
-
I'll have to give this a shot, but I'm facing a deadline here. So this will be an improvement over our beta version - but later. In the meantime, for all of you, I appreciate your input. Unfortunately, I tried a preg_match() and couldn't make it work, and there's no time to piddle with it. What the code does is verifies a userID, then if there are no special characters, and all other fields are inserted properly, establishes a series of database tables, named after the userID, in SQL. This may be a regurgitated thread, but it came in handy when I needed it. We launch our social network site October 12. There's just no time to become a PHP expert in that time frame.
Now, if I could still program that old Sperry in COBOL ... oh, well.Comment
-
I should add, the user setting up their account determines their userID ... and we're not converting anything in the userID field, it simply becomes the name of several new database tables. Hence, we must forbid certain characters that can't be included in a data-table name.Comment
-
You don't have to be an expert to use preg_match. Try this:
I think that will do all your code does, plus cover EVERY character other than letters and numbers.Code:if ( ! preg_match(/^[a-zA-Z0-9]+$/", $userID) ) { // Display error }Comment
-
Thank you! I'll plug this in and run a test. The other code is already live, but this can quickly take its place. I sure picked the wrong week to start learning PHP - LOL!Comment
-
Comment