- Joined
- May 14, 2017
- Messages
- 2
- Reaction score
- 0
I want to make sure the user enters the correct information before moving on to another field. Here is an example:
<script type='text/javascript'>
function emailValidator(element, alertMsg){
var emailvalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(element.value.match(emailvalid))
{
return true;
}else{
alert(alertMsg);
return false;
}
}
</script>
The input in the form:
<h3><font color="#FF0000">*</font> Your E-Mail address: <input
type="text" size="30" name="email" value=" " id="email"
onblur="return emailValidator(document.getElementById('email'), 'This is not a valid Email');"></h3>
Like the codes is, it displays the error message but instead of going back to the email field, it goes on to the next
field input box.
Thanks for your help.
<script type='text/javascript'>
function emailValidator(element, alertMsg){
var emailvalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(element.value.match(emailvalid))
{
return true;
}else{
alert(alertMsg);
return false;
}
}
</script>
The input in the form:
<h3><font color="#FF0000">*</font> Your E-Mail address: <input
type="text" size="30" name="email" value=" " id="email"
onblur="return emailValidator(document.getElementById('email'), 'This is not a valid Email');"></h3>
Like the codes is, it displays the error message but instead of going back to the email field, it goes on to the next
field input box.
Thanks for your help.