D
DM
I'm a newbie in javascript, and came across this problem:
I have a form with several fields, and I need to validate the form. For each
field that needs validation, I include the following:
-------------------------------------
<tr><td >Email:</td><td><input type="text" name="email" value="$email"
onChange="return ValidateEmail(this);"/></td></tr>
-------------------------------------
function ValidateEmail(entered)
{
var re_email=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/
if(re_email.test(entered.value))
{
}
else {
alert("Invalid email.")
}
}
-----------------------------
It works fine... except: if I enter an invalid email it prompts me with an
error message, and continue (without changing the email address), the
validation is not done again. I tried onBlur instead of onChange, but I get
the same results.
Can anyone suggest how to avoid this problem? Thanks.
I have a form with several fields, and I need to validate the form. For each
field that needs validation, I include the following:
-------------------------------------
<tr><td >Email:</td><td><input type="text" name="email" value="$email"
onChange="return ValidateEmail(this);"/></td></tr>
-------------------------------------
function ValidateEmail(entered)
{
var re_email=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/
if(re_email.test(entered.value))
{
}
else {
alert("Invalid email.")
}
}
-----------------------------
It works fine... except: if I enter an invalid email it prompts me with an
error message, and continue (without changing the email address), the
validation is not done again. I tried onBlur instead of onChange, but I get
the same results.
Can anyone suggest how to avoid this problem? Thanks.