0
Validate Date Range - Javascript
LEGEND
,
/t5/dreamweaver-discussions/validate-date-range-javascript/td-p/780013
Apr 20, 2006
Apr 20, 2006
Copy link to clipboard
Copied
Hi Gang,
This is close to a repost... but more of a followup to a thread that has
already moved down everyones list.
I have a pretty simple form validation routine I need to implement, but I
don't know the Javascript syntax well enough to work it out (my background
is VBscript, but this needs to be client side). I received some good URL's
to check out some free scripts.. but unfortunately, I don't know javascript
well enough to hack them up correctly.
If someone can help out with a bit of code, it would be a huge help.
What I need to do is validate a numeric range as well as not leaving the
field blank.
For example what is entered must be a number between 1900 and 2006.
Here is what I am using for the basic required function:
The name of the form is "ThisForm_Right", and the field name is "DOB_Year"
(to explain the 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
This is close to a repost... but more of a followup to a thread that has
already moved down everyones list.
I have a pretty simple form validation routine I need to implement, but I
don't know the Javascript syntax well enough to work it out (my background
is VBscript, but this needs to be client side). I received some good URL's
to check out some free scripts.. but unfortunately, I don't know javascript
well enough to hack them up correctly.
If someone can help out with a bit of code, it would be a huge help.
What I need to do is validate a numeric range as well as not leaving the
field blank.
For example what is entered must be a number between 1900 and 2006.
Here is what I am using for the basic required function:
The name of the form is "ThisForm_Right", and the field name is "DOB_Year"
(to explain the 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/dreamweaver-discussions/validate-date-range-javascript/m-p/780014#M152950
Apr 20, 2006
Apr 20, 2006
Copy link to clipboard
Copied
That's probably because you asked for a fish to help you out
> Can some kind sole help with a modified version to also check for an
> entered
> number range?
and fish can't type.
You're off on the logic though, since something is not likely to be both
blank and outside a certain number range. If it's blank or outside the
range, either condition is sufficient for an error, right?
You also want to make sure that no letters, etc, are entered, because that
will mess up your comparisons to the other numbers. Keeping in mind that
javascript validation can be defeated by sneezing and you'll need to
re-validate on the server, this will be closer to right (not tested).
var ThisYear = ThisForm_Right.DOB_Year.value;
ThisYear = ThisYear.replace(/[^/d]/g,"");
if(ThisYear.length == 0)
{
alert("Please enter the year of your DOB.");
ThisForm_Right.DOB_Year.focus();
return false;
}
else
{
ThisYear = parseInt(ThisYear);
if((ThisYear < 1900) || (ThisYear > 2006))
{
alert ("The year of your DOB must be between 1900 and 2006.");
ThisForm_Right.DOB_Year.focus();
return false;
}
}
> Can some kind sole help with a modified version to also check for an
> entered
> number range?
and fish can't type.

You're off on the logic though, since something is not likely to be both
blank and outside a certain number range. If it's blank or outside the
range, either condition is sufficient for an error, right?
You also want to make sure that no letters, etc, are entered, because that
will mess up your comparisons to the other numbers. Keeping in mind that
javascript validation can be defeated by sneezing and you'll need to
re-validate on the server, this will be closer to right (not tested).
var ThisYear = ThisForm_Right.DOB_Year.value;
ThisYear = ThisYear.replace(/[^/d]/g,"");
if(ThisYear.length == 0)
{
alert("Please enter the year of your DOB.");
ThisForm_Right.DOB_Year.focus();
return false;
}
else
{
ThisYear = parseInt(ThisYear);
if((ThisYear < 1900) || (ThisYear > 2006))
{
alert ("The year of your DOB must be between 1900 and 2006.");
ThisForm_Right.DOB_Year.focus();
return false;
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/dreamweaver-discussions/validate-date-range-javascript/m-p/780015#M152951
Apr 20, 2006
Apr 20, 2006
Copy link to clipboard
Copied
ahh yes, you are right..
I should have said OR instead of AND.
If Field is blank OR range is not between 1900 & 2006. Thanks for catching
and pointing that out.
thanks you so much for the code, I'll test it out and reply with the
results.
Thanks
-Dave
"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:e28b1a$fu5$1@forums.macromedia.com...
> That's probably because you asked for a fish to help you out
>
>> Can some kind sole help with a modified version to also check for an
>> entered
>> number range?
>
> and fish can't type.
>
> You're off on the logic though, since something is not likely to be both
> blank and outside a certain number range. If it's blank or outside the
> range, either condition is sufficient for an error, right?
> You also want to make sure that no letters, etc, are entered, because that
> will mess up your comparisons to the other numbers. Keeping in mind that
> javascript validation can be defeated by sneezing and you'll need to
> re-validate on the server, this will be closer to right (not tested).
>
> var ThisYear = ThisForm_Right.DOB_Year.value;
> ThisYear = ThisYear.replace(/[^/d]/g,"");
> if(ThisYear.length == 0)
> {
> alert("Please enter the year of your DOB.");
> ThisForm_Right.DOB_Year.focus();
> return false;
> }
> else
> {
> ThisYear = parseInt(ThisYear);
> if((ThisYear < 1900) || (ThisYear > 2006))
> {
> alert ("The year of your DOB must be between 1900 and 2006.");
> ThisForm_Right.DOB_Year.focus();
> return false;
> }
> }
>
>
I should have said OR instead of AND.
If Field is blank OR range is not between 1900 & 2006. Thanks for catching
and pointing that out.
thanks you so much for the code, I'll test it out and reply with the
results.
Thanks
-Dave
"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:e28b1a$fu5$1@forums.macromedia.com...
> That's probably because you asked for a fish to help you out
>
>> Can some kind sole help with a modified version to also check for an
>> entered
>> number range?
>
> and fish can't type.

>
> You're off on the logic though, since something is not likely to be both
> blank and outside a certain number range. If it's blank or outside the
> range, either condition is sufficient for an error, right?
> You also want to make sure that no letters, etc, are entered, because that
> will mess up your comparisons to the other numbers. Keeping in mind that
> javascript validation can be defeated by sneezing and you'll need to
> re-validate on the server, this will be closer to right (not tested).
>
> var ThisYear = ThisForm_Right.DOB_Year.value;
> ThisYear = ThisYear.replace(/[^/d]/g,"");
> if(ThisYear.length == 0)
> {
> alert("Please enter the year of your DOB.");
> ThisForm_Right.DOB_Year.focus();
> return false;
> }
> else
> {
> ThisYear = parseInt(ThisYear);
> if((ThisYear < 1900) || (ThisYear > 2006))
> {
> alert ("The year of your DOB must be between 1900 and 2006.");
> ThisForm_Right.DOB_Year.focus();
> return false;
> }
> }
>
>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/dreamweaver-discussions/validate-date-range-javascript/m-p/780016#M152952
Apr 20, 2006
Apr 20, 2006
Copy link to clipboard
Copied
>thanks you so much for the code, I'll test it out and
reply with >the
>results.
Shouldn't that be "Thanks so much for the Cod"?
"Dave Bar" <d@d.com> wrote in message
news:e28c7t$hk1$1@forums.macromedia.com...
> ahh yes, you are right..
> I should have said OR instead of AND.
> If Field is blank OR range is not between 1900 & 2006. Thanks for catching
> and pointing that out.
>
> thanks you so much for the code, I'll test it out and reply with the
> results.
> Thanks
> -Dave
>
>
>
>
> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
> news:e28b1a$fu5$1@forums.macromedia.com...
>> That's probably because you asked for a fish to help you out
>>
>>> Can some kind sole help with a modified version to also check for an
>>> entered
>>> number range?
>>
>> and fish can't type.
>>
>> You're off on the logic though, since something is not likely to be both
>> blank and outside a certain number range. If it's blank or outside the
>> range, either condition is sufficient for an error, right?
>> You also want to make sure that no letters, etc, are entered, because
>> that will mess up your comparisons to the other numbers. Keeping in mind
>> that javascript validation can be defeated by sneezing and you'll need to
>> re-validate on the server, this will be closer to right (not tested).
>>
>> var ThisYear = ThisForm_Right.DOB_Year.value;
>> ThisYear = ThisYear.replace(/[^/d]/g,"");
>> if(ThisYear.length == 0)
>> {
>> alert("Please enter the year of your DOB.");
>> ThisForm_Right.DOB_Year.focus();
>> return false;
>> }
>> else
>> {
>> ThisYear = parseInt(ThisYear);
>> if((ThisYear < 1900) || (ThisYear > 2006))
>> {
>> alert ("The year of your DOB must be between 1900 and 2006.");
>> ThisForm_Right.DOB_Year.focus();
>> return false;
>> }
>> }
>>
>>
>
>
>results.
Shouldn't that be "Thanks so much for the Cod"?
"Dave Bar" <d@d.com> wrote in message
news:e28c7t$hk1$1@forums.macromedia.com...
> ahh yes, you are right..
> I should have said OR instead of AND.
> If Field is blank OR range is not between 1900 & 2006. Thanks for catching
> and pointing that out.
>
> thanks you so much for the code, I'll test it out and reply with the
> results.
> Thanks
> -Dave
>
>
>
>
> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
> news:e28b1a$fu5$1@forums.macromedia.com...
>> That's probably because you asked for a fish to help you out
>>
>>> Can some kind sole help with a modified version to also check for an
>>> entered
>>> number range?
>>
>> and fish can't type.

>>
>> You're off on the logic though, since something is not likely to be both
>> blank and outside a certain number range. If it's blank or outside the
>> range, either condition is sufficient for an error, right?
>> You also want to make sure that no letters, etc, are entered, because
>> that will mess up your comparisons to the other numbers. Keeping in mind
>> that javascript validation can be defeated by sneezing and you'll need to
>> re-validate on the server, this will be closer to right (not tested).
>>
>> var ThisYear = ThisForm_Right.DOB_Year.value;
>> ThisYear = ThisYear.replace(/[^/d]/g,"");
>> if(ThisYear.length == 0)
>> {
>> alert("Please enter the year of your DOB.");
>> ThisForm_Right.DOB_Year.focus();
>> return false;
>> }
>> else
>> {
>> ThisYear = parseInt(ThisYear);
>> if((ThisYear < 1900) || (ThisYear > 2006))
>> {
>> alert ("The year of your DOB must be between 1900 and 2006.");
>> ThisForm_Right.DOB_Year.focus();
>> return false;
>> }
>> }
>>
>>
>
>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
LATEST
/t5/dreamweaver-discussions/validate-date-range-javascript/m-p/780017#M152953
Apr 20, 2006
Apr 20, 2006
Copy link to clipboard
Copied
"Pat Shaw" <pat@nomail.com> wrote in message
news:e28lhv$e7$1@forums.macromedia.com...
> >thanks you so much for the code, I'll test it out and reply with >the
> >results.
>
> Shouldn't that be "Thanks so much for the Cod"?
>
I know cod is good fried. I wonder if sole would match up...
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

