Search the web
Sign In
New User? Sign Up
validation · Techniques for HTML form validation
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Messages 427 - 427 of 427   Newest  |  < Newer  |  Older >  |  Oldest
Messages: Show Message Summaries   (Group by Topic) Sort by Date v  
#427 From: "howardglick" <howardglick@...>
Date: Tue Sep 15, 2009 4:32 pm
Subject: Re: Javascript Field Validation
howardglick
Offline Offline
Send Email Send Email
 
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.
> >
>

Messages 427 - 427 of 427   Newest  |  < Newer  |  Older >  |  Oldest
Advanced
Add to My Yahoo!      XML What's This?

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help