2014-01-29 39 views
2

電子郵件validation`錯誤信息,我需要遠程錯誤信息 下面是我的代碼在jquery電子郵件驗證它是否運行顯示email already existed。它允許和特殊字符also.If它進入[email protected],com顯示已經存在錯誤消息我怎麼能解決這個error.Please幫我如何改變`動態jQuery的

$(document).ready(function() {   

// validate signup form on keyup and submit 
var validator = $("#signupform").validate({ 
    rules: {      
     email: 
     { 
      required: true, 
      minlength: 15, 
      maxlength: 50, 
      remote:"email.php" 
     } 
    }, 
    messages: {    
     email: { 
      minlength: "Email is 15 to 50 characters", 
      maxlength: "Email is 15 to 50 characters",  
      required: " Email should be required", 
      remote: " Email should be already exists"   
     } 
    }, 
      // specifying a submitHandler prevents the default submit, good for the demo  
    submitHandler: function() 
    { 
     alert("submitted!---------"); 
     $("#signupform").submit(); 
    }, 
    // the errorPlacement has to take the table layout into account 
    errorPlacement: function(error, element) 
      {  
     error.prependTo(element.parent().next()); 
    }, 

    // set this class to error-labels to indicate valid fields 
    success: function(label) { 
     // set   as text for IE 
     label.html(" ").addClass("checked"); 
    } 
}); 


// propose username by combining first- and lastname 
$("#username").focus(function() { 
    var firstname = $("#firstname").val(); 
    var lastname = $("#lastname").val(); 
    if(firstname && lastname && !this.value) { 
     this.value = firstname + "." + lastname; 
    } 
}); 
}); 

這是html頁面: -

<form id="signupform" name="signupform" method="post" action="register.php" style="padding-top:70px;" >    
     <table align="center" style="height:200px;">    

       <tr>    
       <td class="field" align="left"><span style="width:150px;color:black;font-weight:bold;">Email:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="email" name="email" style="height:25px;width:155px;" type="text" value="Email Address" onfocus="if(this.value=='Email Address')this.value=''" onblur="if(this.value=='')this.value='Email Address'"/></td> 
       <td class=""></td> 
       </tr>  
       <tr> 
        <td style="width:200px;"><div><font size="1" color="#000000">By clicking 'Register Now' you are agreeing to our <a href="terms_con.php" target="_blank" style="color:red" > Terms and Conditions </a></font></div> </td> 
       </tr> 
      <tr align="">    
       <td class="field" align="" colspan="2" style="padding-left:70px;">   
       <input align="left" value="" id="signupsubmit" name="signup" type="image" src="images/nsignup.png" />      
       </td> 
      </tr> 
     </table> 

    </form> 

這是我的PHP代碼: -

$email=$_REQUEST["email"]; 

    if(eregi('^[a-zA-Z0-9._-][email protected][a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email)) 
     { 
     $sql = "SELECT * FROM users where email='$email'"; 
    $result = mysql_query($sql,$conn); 


     if(mysql_num_rows($result)) 
     {   
      echo 'false'; 
    } 
    else 
     { 
      echo 'true';   
     }   
    } 
    else 
    { 
     echo 'false'; 
    } 
+0

請解釋一點... –

+0

如果我輸入像這樣xxxx @ mail,com它顯示已存在的用戶消息@ \t Ashish Kumar – vamsip

回答

1

JSFiddle

function isValidEmailAddress(emailAddress) { 
    var pattern = new RegExp(/^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/); 
    return pattern.test(emailAddress); 
}; 

使用本

if(isValidEmailAddress('[email protected]')){ 
    alert('ok'); 
} else { 
    alert('faild'); 
} 
+0

問題是** jquery驗證器插件**具體。 –

0

使用本

function IsEmail(email) { 
    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
    return regex.test(email); 
}