- preg_replace: documentation ( source)
<?php
$type = 'login';
$data = 'wolf';
echo FormValid($data,$type);
function FormValid($data,$type){
switch($type){
case 'login':
$edit = preg_replace("/[^A-Za-z0-9]/u", "", $data);
break;
case 'password':
$edit = preg_replace("/[^A-Za-z0-9-_.,]/", "", $data);
break;
}
if($data != $edit){
return false;
}
else{
return $data;
};
}