각종 정규 검증

2242 단어 정칙
$email='[email protected]';

//$pattern='^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$';

//$pattern='^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$';

$pattern='^[_.0-9a-z-]+@([0-9a-z]+.)+[a-z]{2,3}$';

 if (eregi($pattern,$email)) {

	echo "OK";

}else{

	echo"err";

} 


 preg_match 메일박스 검증 방법 (이하 세 가지 방법 모두 가능)
$pattern="/([A-Za-z0-9\_]+)\@([\w\-]+)\.([a-z]{2,3})/";

$pattern2="/(^[A-Za-z0-9\_]+)\@([0-9a-z][0-9a-z-]+)\.([a-z]{2,3}$)/";

$pattern3="/([\w\-]+\@[\w\-]+\.[a-z]{2,3}$)/";

if (preg_match($pattern3,$email)) {

  echo "emailok"; 

}

 
echo"<p> </p>";

$username='sfdsf432_';

$pattern='/[\w]{6,20}/';	

if(preg_match($pattern,$username)){

	echo"username OK";

}	

echo"<p> </p>";

$number='33.25';

$pattern='/^[1-9]([0-9]*)\.(\d+)/';

if(preg_match($pattern,$number)){

	echo"number ok";

}

echo"<p> url</p>";

$url='http://www.163.com/df/?=dsf';

$pattern='/^(http|https):\/\/([\w]+\.)?([\w][\w\-]*)+\.(com|org|net|dk|at|us|tv|info|uk|cn|cc)/';

if(preg_match($pattern,$url)){

	echo"url ok";

}

echo"<p>  ip</p>";

$ip='192.168.1.1';

$pattern='/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/';

if(preg_match($pattern,$ip)){

	echo"ip ok";

}

echo"<p>  html</p>";

$html="<a href=''>sdf</a>";

$pattern="/^<(.*)>.*<\/(.*)>|<(.*) \/>/";

if(preg_match($pattern,$html)){

	echo"html ok";

}


  

좋은 웹페이지 즐겨찾기