jquery - How to finish Javascript Validation Form -


i need create validation form matching passwords, no empty fields, letters/numbers in right fields, date (from , before), age numbers , email appropriate format. managed email thing can me complete javascript code?

body {     line-height: 30px; } .error {     color: red;     font-size: 0.8em;     font-style: italic; } #erroremail {     visibility: hidden; } #errorfname {     visibility: hidden; } 
$(document).ready(function() {     $("input[name='email']").blur(function validateform() {         var x = $("input[name='email']").val();         var pat = /.+@.+\.\w\w\w/;         if (pat.test(x)) {             document.getelementbyid("erroremail").style.visibility = "hidden";         }         if (!pat.test(x)) {             document.getelementbyid("erroremail").style.visibility = "visible";             return false;         }     }); }); 
<form ... method="post" action="" onsubmit="">     <label>username:</label>     <input type="text" name="username" maxlength="16" /><br>      <label>first name:</label>     <input type="text" name="fname" maxlength="24" />      <span class="error" id="errorfname">wrong email format.</span><br>      <label>last name:</label>     <input type="text" name="lname" maxlength="24" /><br>      <label>password:</label>     <input type="password" name="password" maxlength="16" /><br>      <label>confirm password:</label>     <input type="password" name="password2" maxlength="16" /><br>      <label>email:</label>     <input type="text" id="email" name="email" />      <span class="error" id="erroremail">wrong email format.</span><br>      <label>age:</label>     <input type="text" name="age" maxlength="2" /><br>      <label>date:</label>     <input type="date" name="date" /><br><br>      <input type="submit" value="submit" onclick="return validateform(); empty();" /> </form> 

fist off should change javascript around bit.

for form element in html, should handle submit event regarding form. example.

<form ... method="post" action="" onsubmit="validate();"> 

or

<form id="myform"> $("#myform").on('submit',function() {     //handle logic example.      var email = $("input[name='email']").val();     var regex = /\s+@\s+\.\s+/;     if(!regex.test(email)) {         alert("not valid email");         return;     };      //rest of logic.... }); 

a date compare this.

var date = new date($("input[name='date']").val());          var datenow = new date(); // or date.now() if(datenow > date) {    //do stuff } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -