Answers for "javascript valid email not working"

4

how to validate an email address in javascript

function validateEmail(email) 
    {
        var re = /\S+@\S+\.\S+/;
        return re.test(email);
    }
    
console.log(validateEmail('[email protected]'));
Posted by: Guest on June-18-2020
1

How to validate an email address in JavaScript

// Html form call function name at submit button

    <form name="form1" action="#"> 
    <input type='text' name='text1'/>
    <input type="submit" name="submit" value="Submit" 
    onclick="ValidateEmail(document.form1.text1)"/>
   </from>

    // Write the function name ValidateEmail below

    <script>
     function ValidateEmail(inputText)
    {
  var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
    if(inputText.value.match(mailformat))
    {
    alert("Valid email address!");
    document.form1.text1.focus();
    return true;
    }
    else
   {
    alert("You have entered an invalid email address!");
    document.form1.text1.focus();
    return false;
    }
    }
   </script>
Posted by: Guest on August-11-2021

Code answers related to "javascript valid email not working"

Code answers related to "Javascript"

Browse Popular Code Answers by Language