I am trying to validate a business name using preg_match and i'm having trouble with specific characters.
if(!preg_match("/^[0-9A-Za-zÀ-ÿ-!@#$%.'& ]*$/,$businessname){echo "error";}
It seems to work fine except for the ' and &. I've tried escaping them, but still no luck.
charset="UTF-8"
Thank you in advance!
CodePudding user response:
Try this:
$businessname = 'Ásgarðr \'& Óðinn';
if (!preg_match('/^[0-9A-Za-zÀ-ÿ\-!@#$%.\'& ]*$/',$businessname)) {
echo "error";
} else {
echo "passed";
}