
hi......... here is my code could explain it
<html>
<script language = "Javascript">
function checkEmail() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))
{
document.write("You have entered valid email.");
return true;
}
return false;
}
function ValidateEmail(){
var emailID=document.form.email;
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (checkEmail(emailID.value)==false){
emailID.value=""
alert("Invalid Email Adderess");
emailID.focus()
return false
}
return true
}
</script>
<form name="form" method="post" onSubmit="return ValidateEmail()">
Enter an Email Address : <input type="text" name="email" size="30"><br>
<input type="submit" name="Submit" value="Submit">
</form>
</html>`print("code sample");`

<html>
<head>
<title>Email validation using regex</title>
<script type="text/javascript">
function validate() {
var email = document.getElementById("email").value;
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
if (emailPattern.test(email)) {
alert("Email Id: " + email);
return true;
} else {
alert("Email Id is not valid!");
return false;
}
}
</script>
</head>
<body>
<h2>Validating Email Id..</h2>
Email Id :
<input type="text" name="email" id="email" />
<input type="submit" value="Submit" onclick="validate();"/>
</body>
</html>
Description: Email pattern is like abc@ab.aaa. you have to check the pattern of combination of these two. Sometimes space is also included in it.
In pattern /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
/../(forward slashes) is used to quote your regular expression.
^ shows beginning of string.
[..] matches any letter enclosed with in.
+ shows that preceding character come 1 or more times.
\. Shows that \ will treat . as a literal.
{2,4} shows the range that content having length between 2 to 4.
$ is used for ending the string.
test() method takes one argument and check that to the pattern.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.