[PHP] 문자 타입 체크

PHP
function StrTypeCheck($str, $type){ switch ($type){ case "digit": //숫자만 $filter = "'^[[:digit:]]*$'"; break; case "alpha": //영문만 $filter = "'^[[:alpha:]]*$'"; break; case "alnum": //영문,숫자만 $filter = "'^[[:alnum:]]*$'"; break; case "falnum": //영문,숫자만(첫자는 영문) $filter = "'^[a-zA-Z][0-9a-zA-Z]*$'"; break; case "lalpha": //소-영문만 $filter = "'^[a-z]*$'"; break; case "ualpha": //대-영문만 $filter = "'^[A-Z]*$'"; break; case "lalnum": //소-영문,숫자만 $filter = "'^[0-9a-z]*$'"; break; case "ualnum": //대-영문,숫자만 $filter = "'^[0-9a-z]*$'"; break; case "email": //이메일 $filter = "'^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*$'"; break; case "domain": //도메인 $filter = "'^[a-zA-Z0-9]*((-|\.)?[a-zA-Z0-9])*\.([a-zA-Z]{2,4})$'"; break; case "koralnum": //한글숫자영문 $filter = '/^([\xEA-\xED][\x80-\xBF]{2}|[0-9a-zA-Z])+$/'; break; case "koralnumspace": //한글숫자영문공백 $filter = '/^([\xEA-\xED][\x80-\xBF]{2}|[0-9a-zA-Z\s])+$/'; break; case "kor": //한글 $filter = '/^([\xEA-\xED][\x80-\xBF]{2})+$/'; break; } if( preg_match($filter, $str, $matches) ) return true; else return false; }
Read More