PHP have native extension to filter data by either validating or sanitizing it.
if (!filter_var($ip, FILTER_VALIDATE_IP) === false) { echo("$ip is a valid IP address
"); } else { echo("$ip is not a valid IP address
"); } if (filter_var($uuid, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/"))) === false) { echo 'Invalid UUID'; }