JSFiddle - React, Tailwind, and code Playground

by Ryan Brown

HTML

<form name="formValidation" onsubmit="return ValidateForm();" method="post" action="mailto:[email protected]">
  Email:<br>
  <input type="text" name="email" value="asd">
  <br><br>
  <input type="submit" value="Submit">
</form>

JavaScript

function ValidateForm()
{

    var email = document.forms["formValidation"]["email"].value;
    
    //call validate email function and pass in the value
    if (!validateEmail(email)) return false;

    return true;

}

function validateEmail(email)
{
    //create a regular expression and then store it in a variable
    // a link to some regex http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
    email_regex = /^\S+@\S+\.\S+$/;

    // validate the email
    // if your_expression.test(what to test) == false) { do this }
    if (email_regex.test(email) == false) {
        alert( 'Email is not valid' );
        return false;
    }
    return true;
}