Filter allowed chars via PHP

From snippet wiki
Jump to navigation Jump to search

To sanitize user input in webforms, i.e. to get rid of all non-number chars in a telephone input field:

$phone = preg_replace("/[^0-9]+/", "", $phone);

Which leaves only numbers intact.