<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
How to validate email address
using RegExp in JavaScript ?
</
title
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksForGeeks
</
h1
>
<
p
id
=
"GFG_UP"
style
=
"font-size: 15px; font-weight: bold;"
>
</
p
>
<
button
onclick
=
"GFG_Fun()"
>
click here
</
button
>
<
p
id
=
"GFG_DOWN"
style
=
"font-size: 24px; font-weight: bold; color: green;"
>
</
p
>
<
script
>
var up = document.getElementById('GFG_UP');
var down = document.getElementById('GFG_DOWN');
var email = 'GeeksForGeeks@gmail.com';
up.innerHTML = "Click on the button to check the "
+ "validity of Email Id.<
br
>" + email;
function isEmail(email) {
// Regular Expression (Not accepts second @ symbol
// before the @gmail.com and accepts everything else)
var regexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
// Converting the email to lowercase
return regexp.test(String(email).toLowerCase());
}
function GFG_Fun() {
down.innerHTML = isEmail(email);
}
</
script
>
</
body
>
</
html
>