Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Form validation question - Javascript

LEGEND ,
Apr 19, 2006 Apr 19, 2006
Hey Gang,

I'm not too familiar with the syntax of Javascript, so I could use some help
with this (what I suspect is pretty easy).

I have a form field that will have a year value entered. The generic
checking that the field isn't left blank is there.. but I would like to also
check that the value entered is between 19yy and 20yy (not sure of the
actual ranges yet.

Here's my snippet for the filed being blank routine:
The name of the form is "ThisForm_Right", and the field name is "DOB_Year"
(to explain that piece in the code below)

if (ThisForm_Right.DOB_Year.value=="")
{
alert ("Please enter the YEAR of your DOB.");
ThisForm_Right.DOB_Year.focus();
return false;
}

Can some kind sole help with a modified version to also check for an entered
number range?
I suspect some sort of "And" statement, Like
If
(
ThisForm_Right.DOB_Year.Value==""
AND
Year.Value NOT between (1900 and 2006)
)
{
alert ("Please enter the YEAR of your DOB between 1900 and 2006.");
ThisForm_Right.DOB_Year.focus();
return false;
}

I just don't know the real syntax :>
Thanks
-D


TOPICS
Server side applications
327
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 19, 2006 Apr 19, 2006
You should be able to use the javascript function getFullyear() to extract the year from the value of the form field, and check if it is greater than 1899 and less then 2006. Some of the scripts at http://javascript.internet.com/time-date/ might be useful.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2006 Apr 19, 2006
LATEST
Thanks, I'll have a look.

I don't have much knowledge of Javascript syntax (VBScript is more my thing,
but I'd like to do this on the client side), so i'm not sure I can pull the
right things from those scripts, but I'll give it a shot.


"delaneypub" <eharrel1@tampabay.rr.com> wrote in message
news:e25qm7$73d$1@forums.macromedia.com...
> You should be able to use the javascript function getFullyear() to extract
> the
> year from the value of the form field, and check if it is greater than
> 1899 and
> less then 2006. Some of the scripts at
> http://javascript.internet.com/time-date/ might be useful.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines