background image

这篇文章介绍了

php 用户注册页面利用 js 进行表单验证具体实例,有需要的朋友可以参考

一下

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd

§

"> 

<html xmlns="

http://www.w3.org/1999/xhtml

§

"> 

    

<head> 

        

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  

        

<title>用户注册 - php.yl1001.com</title> 

        

<link href="../css/login.css" rel="stylesheet" type="text/css" /> 

        

<link href="../css/page_bottom.css" rel="stylesheet" type="text/css" /> 

        

<script type="text/javascript" src="../js/jquery-1.7.1.js"></script> 

        

<script type="text/javascript"> 

            

var

 flag = { 

                

"email":false, 

                

"nickname":false, 

                

"password":false, 

                

"verify":false 

            

}; 

 

            

$(

function

(){ 

                

$("#txtEmail").blur(

function

 () { 

                                        

var

 email=$(this).val(); 

                                        

//alert(email); 

                                        

if

(email==""){ 

                                            

$("#email\\.info").html("Email 地址不能为空"); 

                                            

return

                                        

                                        

var

 pattern=/\b(^['_A-Za-z0-9-]+(\.['_A-Za-z0-9-]+)*@([A-Za-z0-9-])+

(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/; 

                                        

if

(!pattern.test(email)){ 

                                            

$("#email\\.info").html("Email 格式不正确"); 

                                            

return

                                        

                                        

$.get("check_email.php?email="+email,null, 

                                            

function

(data){ 

                                                

$("#email\\.info").html(data); 

                                                

if

 (data=="可以注册") { 

                                                    

flag.email=true; 

                                                

                                            

                                        

); 

                                    

}); 

                

$("#txtNickName").blur(

function

 () { 

                                            

var

 nickname=$(this).val();