- /**
- * 검증 클래스
- *
- * @lastmodify 2014-5-16
- * @author jy625
- */
- class verifyAction{
- /**
- * null 값인지 여부
- */
- 공개 정적 함수 isEmpty($str){
- $str = 트림($str);
- return !empty($str) ? 사실 : 거짓;
- }
- /**
- * 숫자 확인
- * param:$flag: int가 정수이고 float가 부동 소수점 유형인지 여부
- */
- 공개 정적 함수 isNum($str,$flag = 'float'){
- if(!self::isEmpty($str)) return 거짓;
- if(strtolower($flag) == 'int'){
- return ((string)(int)$str === (string)$str) ? 사실 : 거짓;
- }else{
- return ((string)(float)$str === (string)$str) ? 사실 : 거짓;
- }
- }
- /**
- * 사용자 이름, 디렉터리 이름 등 이름 매칭
- * @param:string $str 매칭할 문자열
- * @param:$chinese 중국어 지원 여부, 기본적으로 지원, 파일 이름과 일치하는 경우 끄는 것이 좋습니다(false).
- * @param:$charset 인코딩(기본값 utf-8, gb2312 지원)
- */
- 공개 정적 함수 isName($str,$chinese = true,$charset = 'utf-8'){
- if( !self::isEmpty($str)) false를 반환합니다.
- if($chinese){
- $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_-] $/" : "/^[x{4e00}-x{9fa5}A-Za -z0-9_] $/u";
- }else{
- $match = '/^[A-za-z0-9_-] $/';
- }
- return preg_match($match,$str) ? 사실 : 거짓;
- }
- /**
- * 이메일 확인
- */
- 공개 정적 함수 isEmail($str){
- if(!self::isEmpty($str)) return false;
- return preg_match("/([a-z0-9]*[-_.]?[a-z0-9] )*@([a-z0-9]*[-_]?[a- z0-9] ) [.][a-z]{2,3}([.][a-z]{2})?/i",$str) ? 사실 : 거짓;
- }
- //手机号码验证
- 공개 정적 함수 isMobile($str){
- $exp = "/^13[0-9]小贝[0-9]{8}$ |15[012356789]작은 부분[0-9]{8}$|18[012356789]작은 부분[0-9]{8}$|14[57]작은 부분[0-9]$/";
- if(preg_match($exp,$str)){
- return true;
- }else{
- false를 반환합니다.
- }
- }
- /**
- * URL 확인은 순수 URL 형식으로, IP 확인을 지원하지 않습니다.
- */
- 공개 정적 함수 isUrl($str){
- if(!self::isEmpty($str)) return false;
- return preg_match('#(http|https|ftp|ftps)://([w-] .) [w-] (/[w-./?%&=]*)?#i', $str) ? 사실 : 거짓;
- }
- /**
- * 중국어 확인
- * @param:string $str 일치시킬 문자열
- * @param:$charset 인코딩(기본값 utf-8, gb2312 지원)
- */
- 공개 정적 함수 isChina($str,$charset = 'utf-8'){
- if(!self::isEmpty($str) ) 거짓을 반환합니다.
- $match = (strtolower($charset) == 'gb2312') ? "/^[".chr(0xa1)."-".chr(0xff)."] $/"
- : "/^[x{4e00}-x{9fa5}] $/u";
- preg_match($match,$str)를 반환합니까? 사실 : 거짓;
- }
- /**
- * UTF-8 유효성 검사
- */
- 공개 정적 함수 isUtf8($str){
- if(!self::isEmpty($str)) return false;
- return (preg_match("/^([".chr(228)."-".chr(233)."]小贝[".chr(128)."-".chr(191)." ]小贝[".chr(128)."-".chr(191)."]小贝)小贝/",$word)
- == true || preg_match("/([".chr (228)."-".chr(233)."]작은정보[".chr(128)."-".chr(191)."]작은정보[".chr(128)."-". chr(191)."]작은 것)작은 것$/",$word)
- == true || preg_match("/([".chr(228)."-".chr(233)." ]小贝[".chr(128)."-".chr(191)."]小贝[".chr(128)."-".chr(191)."]小贝){2,} /",$word)
- == true) ? 사실 : 거짓;
- }
- /**
- * 검증 길이
- * @param: string $str
- * @param: int $type (모드, 기본값 min <= $str <= max)
- * @param: int $ 최소값, 최소값, 최대값
- * @param: 문자열 $charset 문자
- */
- 공개 정적 함수 길이($str,$type=3,$min=0,$max=0,$charset = 'utf-8'){
- if(!self::isEmpty($str)) return false;
- $len = mb_strlen($str,$charset)
- switch($type){
- 사례 1: //다음과만 일치합니다. 가장 작은 값
- return ($len >= $min) ? true : false
- break
- 사례 2: //최대값만 일치
- return ($max >= $len ) ? true: false;
- break
- 기본값: //min <= $str <= max
- return (($min <= $len) && ($len <= $ max) ) ? true : false;
- }
- }
- /**
- * 확인 비밀번호
- * @param string $value
- * @param int $length
- * @return boolean
- */
- 공개 정적 함수 isPWD($value,$minLen=6,$maxLen=16){
- $match='/^[\~!@#$%^&*()-_= |{}
- ,.?/:;'"dw]{'.$minLen.','. $maxLen .'}$/';
- $v = Trim($value);
- if(empty($v))
- return false
- return preg_match($match,$v) ;
- }
- /**
- * 사용자 이름 확인
- * @param string $value
- * @param int $length
- * @return boolean
- */
- 공개 정적 함수 isNames($value, $minLen=2, $maxLen=16, $charset='ALL'){
- if( 비어 있음( $value))
- return false
- switch($charset){
- 케이스 'EN': $match = '/^[_wd]{'.$minLen.','.$maxLen .' }$/iu';
- break
- 케이스 'CN':$match = '/^[_x{4e00}-x{9fa5}d]{'.$minLen.','.$ maxLen.'}$/iu';
- break
- default:$match = '/^[_wdx{4e00}-x{9fa5}]{'.$minLen.','.$maxLen.' }$ /iu';
- }
- return preg_match($match,$value)
- }
- /**
- * 확인 이메일
- * @param string $value
- */
- 공개 정적 함수 checkZip($str)
- if(strlen($str)!=6){
- return false
- }
- if(substr($str,0,1)==0){
- return false;
- }
- true를 반환합니다.
- }
- /**
- * 일치 날짜
- * @param string $value
- */
- 공개 정적 함수 checkDate($str){
- $dateArr =explore("-", $ str)
- if (is_numeric($dateArr[0]) && is_numeric($dateArr[1]) && is_numeric($dateArr[2])) {
- if (($dateArr[0] >= 1000 && $timeArr[0] <= 10000) && ($dateArr[1] >= 0 && $dateArr[1] <= 12) && ($dateArr[2] >= 0 && $dateArr[2 ] < ;= 31))
- true를 반환합니다.
- else
- false를 반환합니다.
- }
- /**
- * 매칭 시간
- * @param string $value
- */
- 공개 정적 함수 checkTime($str){
- $timeArr =explore(":", $str)
- if (is_numeric($timeArr[0]) && is_numeric($timeArr[1]) && is_numeric ($ timeArr[2])) {
- if (($timeArr[0] >= 0 && $timeArr[0] <= 23) && ($timeArr[1] >= 0 && $timeArr[ 1] <= 59) && ($timeArr[2] >= 0 && $timeArr[2] <= 59))
- true를 반환합니다.
- else
- false를 반환합니다.
- false 반환
- }
- }
-
-
- 코드 복사
|
아주 좋아요, PHP