So I can't figure preg_match out. If I am trying to verify that $variable is only letters and numbers and not blank allowing a period, -, space, @ symbol as well would something like this work? If(!preg_match("-@.a-z 1-9", $variable)) { die("statement"); }
You need a delimiting character at either end of your pattern. for example if(preg_match('%^[a-z0-9@. ]+$%i', $subject)) { die('Matched'); }else{ die('No Match'); } PHP: Here's an explaination of what it does (from regexbuddy) ^[a-z0-9@. ]+$ Assert position at the beginning of the string «^» Match a single character present in the list below «[a-z0-9@. ]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A character in the range between “a†and “z†«a-z» A character in the range between “0†and “9†«0-9» One of the characters “@. †«@. » Assert position at the end of the string (or before the line break at the end of the string, if any) «$» Code (markup): add more items to the [ ] if you want more characters matched