
September 12th, 2012, 07:45 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 8
Time spent in forums: 1 h 7 m 15 sec
Reputation Power: 0
|
|
|
Refresh page if user entered the wrong validation
So I have this form.html file with JavaScript validation that will validate if the email that user entered is valid or not, if it is, it will be processed by a php file to enter this email to a MySQL database
Here's the javascrip code:
Code:
<script type='text/javascript'>
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(inputText.value.match(mailformat))
{
document.form1.email.focus();
return true;
}
else
{
alert("invalid email");
document.form1.email.focus();
return false;
}
}
<script>
And here is the form tag in my HTML page
Code:
<form name="form1" action="email.php" method="POST">
<input name="email" type='text' id='email'>
<input type="submit" value="Submit" onclick="ValidateEmail(document.form1.email)"/>
</form>
However, when I entered an invalid email, the error message displays but then it also saves the invalid email into my MySQL database, is there a way to only save the validate email address into the database. So when user enters invalid email, the error message will come up and then will refresh the textbox to allow user to enter again
|