Make sure to put hyphen -
either at start or at end in character class otherwise it needs to be escaped. Try this regex:
^[a-zA-Z0-9 _.,!()+=`,"@$#%*-]*$
Also note that because *
it will even match an empty string. If you don't want to match empty strings then use +
:
^[a-zA-Z0-9 _.,!()+=`,"@$#%*-]+$
Or better:
^[w .,!()+=`,"@$#%*-]+$
TEST:
$text = "_.,!()+=,@$#%*-";
if(!preg_match('/A[w .,!()+=`,"@$#%*-]+z/', $text)) {
echo "error.";
}
else {
echo "OK.";
}
Prints:
OK.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…