JSFiddle - React, Tailwind, and code Playground
by chauhangs
HTML
<form name="myForm" method="post">
<label>*Name:</label>
<input type="text" name="name" title="Enter a your name" placeholder="Your Name" onclick="select()" required/>
<div id="namemsg"></div>
<br/>
<label>*E-mail:</label>
<input type="text" name="email" title="Enter a valid email address" placeholder="[email protected]" onclick="select()" required/>
<div id="emailmsg"></div>
<br/>
<label>*Comment:</label>
<textarea name="comment" title="Enter your comments" placeholder="Enter your comments." onclick="select()" required/></textarea>
<div id="commentmsg"></div>
<label id="error"></label>
<br/>
<input type="submit" value="Submit" onclick="return validateUser();">
</form>
JavaScript
function validateUser() {
var x = document.forms["myForm"]["email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 2 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
document.getElementById("emailmsg").innerHTML = "Not a valid e-mail address";
return false;
}
{
alert("Valid Input");
}
return true;
}