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

Javascript 99.9% there - Thanks to Lionstone

LEGEND ,
Apr 26, 2006 Apr 26, 2006
Hey Gang,

Thanks to Lionstone, I have my javascript function just about perfect.

There's one small item not working, so I thought I'd throw it out there.
The script first checks that a value is entered into a field, then check
that it is betwwen a number range.

At first, it didn't work. It would tell me to enter DOB regardless of what I
put in there.
Then I removed this line for testing:
ThisYear = ThisYear.replace(/[^/d]/g,"");

With that line removed, the script successfully checked for the instance of
an entered value, if something is entered it checked that the number value
is betwwen the number range.

It put up the proper alerts if either criteria wasn't met.

Thing is, I can put alpha characters in there, and it will be accepted.
I suspect that's because the line of code I took out converts the value
entered either into a date, or a number.

Any help checking that last item would be a great help.
Thanks
-Dave

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;
}
}


TOPICS
Server side applications
288
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 26, 2006 Apr 26, 2006

"Dave Bar" <d@d.com> wrote in message
news:e2ogi9$crl$1@forums.macromedia.com...
> At first, it didn't work. It would tell me to enter DOB regardless of what
> I put in there.
> Then I removed this line for testing:
> ThisYear = ThisYear.replace(/[^/d]/g,"");
>

The slash is backward. Typos are fun, eh? Sorry about that.

ThisYear = ThisYear.replace(/[^\d]/g,"");


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 26, 2006 Apr 26, 2006
I guess I should clarify for you - that line removes all alpha characters,
punctuation, anything that isn't a digit. After all that is scrubbed out,
it checks to see if anything's left. If nothing is left, you get a "please
enter your dob" message. If what's left is a number not between 1900 and
2006, you get the "your year doesn't make sense" message.

There are other ways you could handle this, such as using a regex to test
for 4 digits (if not "I can't recognize your year - please enter a 4-digit
year.") and then convert to number and test the range.

Either way.

"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:e2ol0j$ijh$1@forums.macromedia.com...
> ThisYear = ThisYear.replace(/[^\d]/g,"");
>


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 26, 2006 Apr 26, 2006
LATEST
Lionstone... thanks again!!



"Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
news:e2ol8p$j13$1@forums.macromedia.com...
>I guess I should clarify for you - that line removes all alpha characters,
>punctuation, anything that isn't a digit. After all that is scrubbed out,
>it checks to see if anything's left. If nothing is left, you get a "please
>enter your dob" message. If what's left is a number not between 1900 and
>2006, you get the "your year doesn't make sense" message.
>
> There are other ways you could handle this, such as using a regex to test
> for 4 digits (if not "I can't recognize your year - please enter a 4-digit
> year.") and then convert to number and test the range.
>
> Either way.
>
> "Lionstone" <HIDElionstone@HIDEhushmail.com> wrote in message
> news:e2ol0j$ijh$1@forums.macromedia.com...
>> ThisYear = ThisYear.replace(/[^\d]/g,"");
>>
>
>


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