Home  >  Article  >  Web Front-end  >  jQuery implementation of form validation example for user registration_jquery

jQuery implementation of form validation example for user registration_jquery

WBOY
WBOYOriginal
2016-05-16 17:23:591232browse
Copy code The code is as follows:



< ;meta charset="utf-8"/>

<script> <br>$(function(){ <br>$(":input.required").each(function(){ <br>var $required = $("<strong>* </strong>"); <br>$(this).parent().append($required); <br>}); <br>$(":input.required").blur(function() { <br>//Determine who the mouse left is<br>if($(this).is("#username")){ <br>$(".formtip").remove(); <br>/ /Verify according to the rules of username<br>if(this.value==""||this.value.length<6){ <BR>var errMsg = "<span class='formtip'>Username At least 6 letters</span>"; <br>$(this).parent().append(errMsg); <br>}else{ <br>var msg = "<span class='formtip' >Username can use</span>"; <br>$(this).parent().append(msg); <br>} <br>} <br>//Check if it is an email, It should be verified according to the rules of email <br>if($(this).is("#email")){ <br>$(".emailtip").remove(); <br>//Follow the rules of email To verify <br>var reg = /^w{1,}@w .w $/; <br>var $email = $("#email").val(); <br>if(!reg.test ($email)){ <br>var errMsg = "<span class='emailtip'>Illegal email address</span>"; <br>$(this).parent().append(errMsg); <br>}else{ <br>var Msg = "<span class='emailtip'>The email can be used</span>"; <br>$(this).parent().append(Msg); <br>} <br>} <br>}); <br><br><br>}) <br></script>




Username:


Email:


Personal information:





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn