[ACCEPTED]-Regex to enforce alpha-numeric but allow apostrophes and hyphens?-regex
Accepted answer
Just include the single apostrophe and the 1 hyphen at the end of the range:
function sanitize_string($s) {
$result = preg_replace("/[^a-zA-Z0-9'-]+/", " ", html_entity_decode($s, ENT_QUOTES));
return $result;
}
Trying to get an answer to you as quick 5 as I can.
I think you can just add them into 4 the character class; possibly you'll need 3 to escape them though.
Note: to use the -
be 2 sure to put it at the end otherwise it will 1 be considered a meta character.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.