Flipkart

Wednesday, July 15, 2009

Url, Email Validation

function validate() {
var url=document.getElementById("url").value;
if(url=='') {
alert("url should nt be empty");
}else {   
var v = new RegExp();
v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
if (!v.test(url)) {
alert("wrong url");
}else{
alert("url ok");}
}

}


Email Validation:

function validate(){

var email=document.getElementById('email').value;
if(email=='') {
alert('email should nt be empty');
}else {    
var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!regex.test(email)) {    
alert('wrong email');
}else{
alert('Email ok');}
}
}


1 comment:

  1. That's just simply wonderful.. I have this new website that is about to be released at the end of July, and I was looking for some email validation tools that I can use for it.. I'm gonna check this out and share this with my friends if everything goes well.. Thanks!

    Email validation software

    ReplyDelete