Location: PHPKode > scripts > CheckRegExp > checkregexp/CheckRegExp.php
<?php
class CheckRegExp {
	public static function checkMail($string){
		$mail = "/^[^@]*@[^@]*\.[^@]*$/";
		return self::check($string,$mail);
	}
	public static function checkIP($string){
		$ip = "/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/";
		return self::check($string,$ip);
	}
	public static function checkHexColor($string){
		$hex = "/^#[a-fA-F0-9]{6}$/";
		return self::check($string,$hex);
	}
	public static function checkHexNumber($string){
		$hex = "/^[a-fA-F0-9]{6}$/";
		return self::check($string,$hex);
	}	
	public static function checkInteger($string){
		$integer = "/^[-+]?\b[0-9]+(\.[0-9]+)?$/";
		return self::check($string,$integer);
	}
	public static function checkFloat($string){
		$float = "/^[-+]?\b[0-9]*\.?[0-9]+$/";
		return self::check($string,$float);
	}
	
	public static function checkUsername($string){
		$username = "/^[a-z\d_]{4,28}$/i";
		return self::check($string,$username);
	}
	
	private function check($string,$regexp){
		if (preg_match($regexp,	$string))
			return true;
		return false;
	}
}

?>
Return current item: CheckRegExp