I am trying to get this Regex to work to validate a Name field to only allow A-Z, \' and -.
So far I am using this which is working fine apart from it wont allow an
if (preg_match("/^[A-Z'-]+$/",$firstname)) { // do something }
The caret ^ inside a character class [] will negate the match. The way you have it, it means if the $firstname contains characters other than a-z, A-Z, ', and -.
^
[]
$firstname
a-z
A-Z
'
-