$text=" this is test characters - and ,"; if (ereg(^[A-Za-Z0-9_ -,)){ echo "error message" } When i am testing this function for comma (',') symbol this is not working.Only i am having prblem with comma.Is ereg not work for "," ?
Im not the best with regex but try if (ereg('[^A-Za-z0-9_,\-]',$text)){ //any character that is not alphanumeric, underscore, comma, or hyphen echo "error message"; } PHP:
Stop using ereg* functions. They're very insecure and deprecated. Use preg_match() instead. And it's unclear what you're trying to do. Do you want to check if any of those characters are in the string? Or at the beginning of the string? Because that's what the ^ at the beginning of the pattern means.