Checking a string
Moderator: General Moderators
Checking a string
Hi again. How would i check a variable if it contained any special characters? IE + ! " £ $ % ^ & * ( ) ; ' # ] [ , . / \ ¬ ` | ¦ { } ~ @ : ? > < - =.
well, can you tell us what you are using this for?
Is this for a username sign-up script and you want to eliminate the possibilty of them using special characters?
This data could be helpful in assiting you. Depending on what your using this for, this regEx would only allow characters 0-9, a-z(capital or lowercase) to be allowed as well as a underscore and -.
Is this for a username sign-up script and you want to eliminate the possibilty of them using special characters?
This data could be helpful in assiting you. Depending on what your using this for, this regEx would only allow characters 0-9, a-z(capital or lowercase) to be allowed as well as a underscore and -.
Code: Select all
<?php
if (!ereg("^[_a-zA-Z0-9-]+$", $name)) {
echo "no special chars allowed.";
} else {
// do whateevr
}
?>and if you wish to avoid regEx as much as possible (some people just hate them)
read: http://us2.php.net/manual/en/ref.ctype.php
But if this is not what your looking for, please let us know what you are wishing to accomplish
read: http://us2.php.net/manual/en/ref.ctype.php
But if this is not what your looking for, please let us know what you are wishing to accomplish