Table of Contents
All Small Letters
JavaScript Code
Small Letter Validations
Complex Password
JavaScript Code
Complex Password Validation
Checking if Password Contains
- Minimum one Special Character
- Minimum one Lower Case Alphabet
- Minimum one Upper Case Alphabet
- Minimum one Numerical Value
Confirm Password
HTML Code
JavaScript Code
function formvaliconfirm(){
var pass=document.form1.passward.value;
var passconfirm=document.form1.passwardconfirm.value;
if
(!(pass==passconfirm)){alert("please enter a correct passward")}
}
Email Validation
HTML Code
JavaScript Code
function formvaliemail(){
var email=document.form1.emailid.value;
var c=email.indexOf("@");
var d=email.indexOf(".");
var e=email.lastIndexOf(".");
var f=email.length;
var g=e+4;
var j=c+5;
if
(email==""){alert("please enter a value")}
else if(c==-1)
{alert("please enter a value with @")
}
else if(d==-1)
{alert("please enter a value with .")
}
else if(ef)
{alert("please enter3 values after last dot(.)")
}
else if(j>e)
{alert("please enter5 values after@ & last dot(.)")
}
}
Math Function in Form Validations
1. length
2. indexOf
3. lastIndexOf
4. charCodeAt
5. charAt
6. Nan
Mobile validation
HTML Code
JavaScript Code
function formvalimobile(){
var mob=document.form1.mobile.value;
if
(mob==""){alert("please enter a value")}
else if
(isNaN(mob)){alert("please enter a numerical value")}
else if(!(mob.length==10)){alert("please enter a value of 10 digit for India")
}
else if(!(mob.charAt(0)==9))
{alert("please enter a first digit with 9")
}
else if(!(mob.charAt(1)==9))
{alert("please enter a second digit with 9")
}
}
Name validation
HTML Code
JavaScript Code
function formvaliname(){
var nm=document.form1.username.value;
if
(nm==""){alert("please enter a value")}
else if
(!(isNaN(nm))){alert("please enter first letter alphabetical")}
else if
(nm.length<5){alert("please enter minimum 5 letters")}
else if
(nm.indexOf(" ")==-1){alert("please enter sur name")}
}
Password Validation
HTML Code
JavaScript Code
function formvalipassward(){
var pass=document.form1.passward.value;
if
(pass==""){alert("please enter a value")}
else if
(pass.length<8){alert("please enter minimum 8 letters")}
}