Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Date problems in Safari Browser only

Reply
Thread Tools

Date problems in Safari Browser only

 
 
ipy2006
Guest
Posts: n/a
 
      12-26-2006
Only in Safari browser the current year shows as 1970. Also "Non digits
found in year" is triggered in the Safari broswer. Please help.
Thanks,
Yasaswi

function verifyYear( field )
{
var _x = field.value;

var _exp = new RegExp(/^\d+$/);
var _test=_exp.test(_x);

var _currentDate = new Date();

var yy = _currentDate.getUTCFullYear();

alert("entered year is : " + _x + " current year is : " + yy );

if(_x.length!=4) {
alert("Please enter four digit year.");
return false;
}
else if(!_test) {
alert("Non digits found in year.");
return false;
}
else if( _x > yy ) {
alert("You entered a year in the future. Please enter valid year."
);
return false;
}
else {
return true;
}

}

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      12-26-2006
ipy2006 wrote on 26 dec 2006 in comp.lang.javascript:

> Only in Safari browser the current year shows as 1970. Also "Non
> digits found in year" is triggered in the Safari broswer. Please help.
> Thanks,
> Yasaswi
>
> function verifyYear( field )
> {
> var _x = field.value;
>
> var _exp = new RegExp(/^\d+$/);
> var _test=_exp.test(_x);
>
> var _currentDate = new Date();
>
> var yy = _currentDate.getUTCFullYear();
>
> alert("entered year is : " + _x + " current year is : " + yy );
>
> if(_x.length!=4) {
> alert("Please enter four digit year.");
> return false;
> }
> else if(!_test) {
> alert("Non digits found in year.");
> return false;
> }
> else if( _x > yy ) {
> alert("You entered a year in the future. Please enter valid
> year."
> );
> return false;
> }
> else {
> return true;
> }
>
>}


I don't know Safari,
but .getUTCFullYear() should be valid from Safari 1.2.


You make a rather complex code,
with al those spurious "else" clauses after a return.
[Please do not use tab chars in a code on usenet]
try:


function verifyYear( field ) {
var x = field.value;
var y = new Date().getUTCFullYear();
alert("entered year is : " + x + " current year is : " + y );

if( x.length != 4 ) {
alert("Please enter four digit year.");
return false;
};

if(/[^\d]/.test(x)) {
alert("Non digits found in year.");
return false;
};

if( x > y ) {
alert("You entered a year in the future. Please enter valid year.");
return false;
};

return true;
}



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      12-27-2006
In comp.lang.javascript message <(E-Mail Removed)
glegroups.com>, Tue, 26 Dec 2006 12:38:59, ipy2006 <(E-Mail Removed)>
posted:
>Only in Safari browser the current year shows as 1970.


Then you should alert(_currentDate) to see what you are getting.

> Also "Non digits
>found in year" is triggered in the Safari broswer.


Then you should alert(_x) to see what you are getting.

>function verifyYear( field )
>{
> var _x = field.value;
>
> var _exp = new RegExp(/^\d+$/);


or. reversing logic, /\D/

> var _test=_exp.test(_x);
>
> var _currentDate = new Date();
>
> var yy = _currentDate.getUTCFullYear();
>
> alert("entered year is : " + _x + " current year is : " + yy );


Entered year is by local civil time. Current year is UTC. They should,
generally, not be compared.

> if(_x.length!=4) {
> alert("Please enter four digit year.");
> return false;
> }
> else if(!_test) {
> alert("Non digits found in year.");
> return false;
> }
> else if( _x > yy ) {
> alert("You entered a year in the future. Please enter valid year."
>);
> return false;
> }
> else {
> return true;
> }
>
>}


An "else" is nor needed after "if ... return ...".


--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
page load on date selection from custom javascript date picker on safari 3.0.4 bala2008 ASP .Net 0 06-27-2008 04:14 AM
Problems getting attribute xlink:href in Safari browser Lance Dyas Javascript 4 10-06-2005 02:47 AM
Problems with anchors, ONLY IN SAFARI Steve K HTML 3 06-24-2005 12:33 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM



Advertisments