Saturday, 18 January 2014

Validate Email Address in JQuery

Description:

  In this article, I am going to write JQuery code examples to Validate Email Address in JQuery by using different type of  Regular Expression filters in client side.

Summary:


Validate Email in JQuery using Regular Expression - 1

   You can use and alter the following JQuery function to Check and Validate an Email address, then you can say confirmation to user about the user has entered valid Email ID or not.
<html>
<head>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /[\w-]+@([\w-]+\.)+[\w-]+/;
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Validate Email in JQuery with Regular Expression</h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 

Validate Email Address in JQuery with Regular Expression - 2

   You can use and alter the following JQuery function to Validate an Email Address from client side.
<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Validate Email ID in JQuery using Regular Expression</h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 

Validate Corporate Email in JQuery using Regular Expression - 3

   You can use the following JQuery function for Domain specific Email validation in JQuery from client side. Here, if you enter the email address with domains gmail.com,yahoo.com,hotmail.com and live.com, the checkMail function throws alert 'Please enter a valid email address'. By using this you can force user to enter only Corporate Email Address and stop user from entering some unwanted Email Domain Address.
<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!live.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Validate Domain specific Email Address in JQuery using Regular Expression</h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 

Email validation in JQuery using Regular Expression - 4

   You can use and alter the following JQuery function to validate and test an Mail Address from client side.
<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Email validation in JQuery using Regular Expression</h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 

Validate case sensitive Email Address in JQuery using Regular Expression - 5

   You can use the following JQuery function to validate Case Sensitive Email Address in JQuery. This function check and allow only lower case letters in email address.
<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Validate case sensitive Email Address in JQuery </h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 


Validate Email in JQuery using Regular Expression - 6

   You can use the following JQuery function to check Email Address is valid or not in JQuery using Regular Expression from client side.
<html>
<head>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script>
 
function checkEmail() {
 
    var email=$('#txtEmailID').val();
    var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
 
    if (!filter.test(email)) {
    alert('Please enter a valid email address');
    return false;
 }
  else{
  alert('Nice!..you have entered valid email address');
  }
}
</script>
</head>
<body>
 
<h1>Validate Email in JQuery using Regular Expressiont</h1>
 
<input type='text' id='txtEmailID'/>
<button type="button" onclick="checkEmail()">Validate Mail</button>
 
</body>
</html> 


Advertisements
Advertisements

1 comment: