Select Language



Followers

IT Programmer. Powered by Blogger.

15 March 2012

Create A Strong Email Validation Using Javascript

"Om Swastiastu"

Previously, I have posted an article about how to make a simple email validation using javascript. And now I want to make the same article but a stronger email validation using javascript. I don't to waste your time here, so let's get started.

First please make a textbox and a button. Copy this script:

<input type="text" id="email">

<input type="button" onclick="checkEmail()">

Then after you made textbox and button, you can start made the validation script using javascript. Follow the code below:

function checkMail(){
var validator = true;
var location = text.indexOf('@');
var dotPos = text.indexOf('.');

if(text.indexOf('@')==-1 || text.indexOf('@')==0 || text.indexOf('@')==text.length){
validator=false;
}

if(text.indexOf('.')==-1 || text.indexOf('.')==0 || text.indexOf('.')==text.length){
validator=false;
}

if(text.indexOf('@',(location+1))!=-1){
validator=false;
}

if(text.substring(location-1,location)=='.' || text.substring(location+1,location+2)=='.'){
validator=false;
}

if(text.substring(dotPos+1, dotPos+2) == '.'){
validator=false;
}

if(text.indexOf('.',(location+2))==-1){
validator=false;
}

if(text.indexOf(" ")!=-1){
validator=false;
}

if(text.charAt(text.length-1) == "."){
validator=false;
}

if(validator == false){
alert("The email entered is not valid");
}else{
alert("The email entered is valid");
}
}



The validation above is strong enough. You can use this script when you make your homework or assignment when your lecturers doesn't allow you to use javascript framework like JQuery. So this is pure javascript email validation.

"Om Santhi, Santhi, Santhi, Om"



Comments:

Ada 0 comments pada “Create A Strong Email Validation Using Javascript”

Social Media


Facebook Page

Programming Tutorial


Info


Tips
Downloads
Friends
 
This Blog is proudly powered by Blogger.com | Template by Bali Web Development | Privacy Policy | Rise Up!!