1function validateEmail (emailAdress)
2{
3 let regexEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
4 if (emailAdress.match(regexEmail)) {
5 return true;
6 } else {
7 return false;
8 }
9}
10
11let emailAdress = "test@gmail.com";
12console.log(validateEmail(emailAdress));
13
1function validateEmail(email) {
2 const re = /^(([^<>()\[\]\\.,;:\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,}))$/;
3 return re.test(String(email).toLowerCase());
4}
1Author:Mohammad Arman Khan
2//E-mail valiadtion using Regex
3var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
4 if (!pattern.test(input["email"])) {
5 isValid = false;
6 errors["email"] = "Please enter valid email address.";
7 return isValid;
8}else{
9 isValid = true;
10 return isValid;
11}
1// onclick function
2function validEmail() {
3 const regularExpresionForEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
4 const input = document.getElementById('input')
5 const inputValue = input.value;
6
7 if (inputValue.match(regularExpresionForEmail)) {
8 const successmsg = document.getElementById('text');
9 successmsg.innerHTML = `<p class="text-success">Your Input is Valid</p>`
10
11 } else {
12 const msg = document.getElementById('text');
13 msg.innerHTML = `<p class="text-danger">Input Valid charecter! </p>`
14
15 }
16 input.value = '';
17}