if(preg_match(\'/[^a-z\\-0-9]/i\', $value))
{
echo \"\";
}
how
Assuming you are talking about the regex, you escape both with a slash \
.
/[^a-z\.\-0-9]/i
The hyphen does not need to be escaped if it is the last character in the Regex group. But the dot should always be escaped, so
'/[^a-z\.0-9-]/i'
Will check for a to z, . , 0 to 9 and - in that order, case insensitively.
The hyphen
doesn't need to be escaped if it's the first or last in the character class.
The dot
also doesn't need to escaped when used inside a character class []
i.e.:
/[^a-z.0-9-]/i
NOTES:
Apart from the above, the meta characters that also need to be escaped inside a character class are:
^ (negation)
- (range)
] (end of the class)
\ (escape char)
The hyphen is already in there, simply add an escaped dot using \.
.
/edit: But as noted in the comment the escaping isn't needed.