I have this javascript code:
function validate()
{
var email=document.getElementById('email').value;
var emailRegex=/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/;
var emailResult=emailRegex.test(email);
alert("email:" +emailResult);
}
and the html part, on a form tag:
<input type="text" id="email" placeholder="EMAIL"><br><br>
<input type="submit" value="REGISTER" id="butt">
I want to print a message everytime that the test of Regex returns false,but I don't want to use an alert box. How can I do this?
Form :
<form id="registration" onsubmit="validate()">
<h3>S'ENREGISTRER</h3>
<label for="button">FULL NAME: </label>
<small>*</small>
<input type="text" name="fname" id="fullname" placeholder="FULL NAME"><br><br>
<label for="button">LAST NAME:</label>
<small>*</small>
<input type="text" name="lname" id="lastname" placeholder="LAST NAME"><br><br>
<label for="button">USERNAME:</label>
<small>*</small>
<input type="text" name="uname" id="username" placeholder="USERNAME"><br><br>
<label for="button">PASSWORD:</label>
<small>*</small>
<input type="password" name="pass" id="password" placeholder="PASSWORD"><br><br>
<label id = "kjo" for="button">EMAIL:</label>
<small>*</small>
<input type="text" id="email" placeholder="EMAIL"><br><br>
<input type="submit" value="REGISTER" id="butt" onclick="validate()">
<p id="result"></p>
<br><br>
<a href="login.html">LOGIN</a>
</form>
element tag and use .innerHtml to display the result in
tag
– Elvis Wong May 26 '18 at 15:36