pTutorial

New way to learn Programming

Java Script email validation with JQuery

JavaScript : HTML Form - email validation

Mostly every form has email field and email ID play important role at every time when you are trying registered with any website. In this section we have discussed how to validate email Id with the help of JavaScript and JQuery.

Regular expression for email validation

function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (inputText.match(mailformat)){
return true;
}
else{
return false;
}
}  

JavaScript email validation example

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/
libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function (e) {
$('#kk').click(function () {
var z=$('#uk').val();
if(z==''){
alert("Please enter email");
}
else if(ValidateEmail(z)){
alert("You have entered "+z);
return false;
}else{
alert("Please enter valid email id");
return false;
}
});
});

function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (inputText.match(mailformat)){
return true;
}
else{
return false;
}
}   
</script>
<style>
table{
border: 1px solid #080808;
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<h4>Email validation</h4>
<table id="tab">
<tr>
<td>Enter Email Id *</td>
<td> <input type="text" id="uk" name="kk1"></td>
<span></span>
</tr>
<tr>
<td> <input type="submit" id="kk" value="Check"></td>
</tr>
</table>
</body>
</html>

Download

See Also


QUOTES OF THE DAY

A good beginning makes a good ending.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER