Check string for special chars help
Question posted by: gamernaveen
(Newbie)
on
May 9th, 2008 04:13 PM
I wanted to include a string invalid character check in my application.
Like the field comment , if a user inserts any special characters
(Except '[' , ']' , '@' , '/' , '=' and numbers - alphabets) , the function should return true , if the string contains no special char in any position , the function should return false.
Can anyone design a function to check the special chars ?
Thanks so much.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Re: Check string for special chars help
So, there HAS to be a special char in the string?
Ok, so, you can preg_match()
Code: ( text )
<?php $_string = "thisisagoodstring*"; $_stringbad = "thisisabadstring"; if(preg_match('#[^a-zA-Z0-9]#', $_string)) { echo "special char found!"; } ?>
|
|
May 10th, 2008 07:56 AM
# 3
|
Re: Check string for special chars help
Quote:
Originally Posted by gamernaveen
I wanted to include a string invalid character check in my application.
Like the field comment , if a user inserts any special characters
(Except '[' , ']' , '@' , '/' , '=' and numbers - alphabets) , the function should return true , if the string contains no special char in any position , the function should return false.
Can anyone design a function to check the special chars ?
Thanks so much.
|
On your free time, I recommend looking into regular expressions. They will seam over-whelming at first and many sites will go deep into it, but learning the basics will help you alot.
In coding (your IDE's Find and Replace feature) AND in your code.
Have fun,
-Dan
Not the answer you were looking for? Post your question . . .
170,099 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Top PHP Forum Contributors
|