Possible Duplicate:
regular expression for letters, numbers and – _
I would like to return true if the $var only includes (A-Z, a-z, 0-9 and –)
Something like: (this preg_match is to check if $var is mail, but I need the above)
if (!preg_match("/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i", $var))
return false;
return true;
Any ideas? Im new with preg_match.
You need to use this preg_match with the code you provided:
It will match if
$varincludes only (A-Z, a-z, 0-9 and -) and is at least 1 character long. If you want to match also empty strings turn the+in a*.