Java-Script Validation can be used in portal in html , php , java etc .
1. Email Validation : We have used an Regex here , and compared the text in input with it and given an alert.
function validateemail() {
var ccc = document.getElementById( ‘idemailtb’).value;
var reg = /^w+([-+.’]w+)*@w+([-.]w+)*.w+([-.]w+)*$/
if (!reg.test(ccc)) {
alert( “Invalid Email Id”);
}
2. Contact No. Validation : We have used an simple if condition that Number should be atlest of 10 in length.
function permanentnumber() {
var mob = document.getElementById( ‘idcontactnotb’).value;
var count = mob.length;
if (mob > 31 && (mob < 48 || mob > 57) && count == 10 ) { }
else {
alert( “Please Enter 10 Digit Number:” );
return true;
}
}
2. Zipcode / Pincode Validation : We have used an simple if condition that ZipCode should be atlest of 6 in length and only a numerical value .
function zipcode() {
var zipcode = document.getElementById( ‘idziptb’).value;
var length = zipcode.length
if (length < 6)
alert( “Please Enter Valid Zipcode:”);
if (zipcode > 31 && (zipcode < 48 || zipcode > 57)) { return false; }
else {
alert( “Please Enter Valid Zipcode:”);
return true;
}
}
SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012