Contact: aviboots(AT)netvision.net.il
39,851 questions
51,772 answers
573 users
function isValidString($s) { $pattern = '/^[A-Za-z0-9_-]*$/'; return preg_match($pattern, $s); } $s1 = "-abc_123-"; echo isValidString($s1) ? "yes\n" : "no\n"; $s2 = "-abc_123-(!)"; echo isValidString($s2) ? "yes\n" : "no\n"; /* run: yes no */