I have tried removing the return true, but it then ignores the statements. I
realise there is probably more than meets the eye on this and that I may need to
adjust the statement.
--- In validation@yahoogroups.com, "somematt" <matthew.a.frank@...> wrote:
>
> rather than return true, you simply want to continue processing. the return
statement will prevent execution of any other statements in your function.
>
> --- In validation@yahoogroups.com, "howardglick" <howardglick@> wrote:
> >
> > I am new to writing Javascript and also somewhat restricted as the my
companies CMS allows me to enter JS into the body, but I do not have access to
the head. This appears to work for simple validation, but I am having problems
with regular expressions working correctly.
> >
> > The script is as follows: -
> >
> > <script type="text/javascript">
> > function validate_required(field,alerttxt)
> > {
> > with (field)
> > {
> > if (value==null||value=="")
> > {
> > alert(alerttxt);return false;
> > }
> > else
> > {
> > return true;
> > }
> > }
> > }
> >
> > function validate_form(thisform) {
> > with (thisform) {
> >
> > if (validate_required(firstname,"A value must be entered for First
Name")==false)
> > {firstname.focus();return false;}
> >
> > if (validate_required(lastname,"A value must be entered for Last
Name")==false)
> > {lastname.focus();return false;}
> >
> > if (validate_required(emailaddress,"A value must be entered for
Email")==false)
> > {emailaddress.focus();return false;}
> >
> > if (validate_required(companyname,"A value must be entered for Company
Name")==false)
> > {companyname.focus();return false;}
> >
> > if (validate_required(phonenumber,"A value must be entered for Phone
Number")==false)
> > {phonenumber.focus();return false;}
> >
> > if (validate_required(city,"A value must be entered for City")==false)
> > {city.focus();return false;}
> >
> > if
(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(thisform.emailaddress.valu\
e))
> > {return true;}
> >
> > {alert("An invalid Email has been entered")
> > return false;}
> >
> > if
(/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/.te\
st(thisform.phonenumber.value))
> > {return true;}
> >
> > {alert("An invalid Phone Number has been entered")
> > return false;}
> >
> > }
> > }
> >
> > I am having problems with the last 2 if statements, the first one works and
correctly validates the email address but the second one (to validate the phone
number) is ignored.
> >
>
|