JSFiddle - React, Tailwind, and code Playground

by Sean Wessell

HTML

<input type="text" id="questionSearchInput" placeholder="question" value="This is my question..." />
<input type="text" id="emailTextInput" placeholder="email" value="[email protected]" />
<button type="submit" id="newWay">submit New Way</button>
<button type="submit" id="oldWay">submit Old Way</button>

JavaScript

//according to http://stackoverflow.com/a/2049510/4338570
//-Uppercase and lowercase English letters (a-z, A-Z)
//-Digits 0 to 9
//-Characters ! # $ % & ' * + - / = ? ^ _ ` { | } ~
//-Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
//are allowed in email

function submitQuestionFunction() {

    var question = $("#questionSearchInput").val();
    var email = $("#emailTextInput").val();
    var emailRegEx = /^([\w-]+(?:(\!|\#|\$|\%|\&|\=|\*|\+|\/|\?|\^|\~|\||\.|\}|\{)[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

    if (question == null || question == "") {
        alert("you must ask a question");
        return false;
    } else if (email == null || email == "") {
        alert("you must Fill in your email");
        return false;
    } else if (emailRegEx.test(email) == false) {
        alert("Not a valid e-mail address");
        return false;
    } else {

        //$.post("askQuestion.php", {"question":question, "email":email}, function(data){
        //console.log(data);
        //location.href = "http://www.example.com/questionAsked.html";
        //});
        alert("everything is valid POST!");
        return true;
    }

}

function submitQuestionFunctionOld() {
    var question = document.getElementById("questionSearchInput").value;
    var email = document.getElementById("emailTextInput").value;
    if (question == null) {
        alert("you must ask a question");
        return false;
    }
    if (question == "") {
        alert("you must ask a question");
        return false;
    }
    if (email == null) {
        alert("you must Fill in your email");
        return false;
    }
    if (email == "") {
        alert("you must Fill in your email");
        return false;
    }
    var atpos = email.indexOf("@");
    var dotpos = email.lastIndexOf(".");
    if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >=...