473,503 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript version of VBScript's formatting functions

Hi,

Does anyone know of a "definitive" source of JavaScript formatting functions
e.g. to format numbers, dates, currencies etc?

There are loads of examples on the Internet, of course, but I've yet to find
any which are 100% reliable.

Mark
Nov 19 '05 #1
11 1549
No site is going to be 100% guaranteed... heck, nothings perfect.
As for "best you will find"... well, that's another story.
I've always used www.DevGuru.com for my javascript syntax and found it quite
nice.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Mark Rae" wrote:
Hi,

Does anyone know of a "definitive" source of JavaScript formatting functions
e.g. to format numbers, dates, currencies etc?

There are loads of examples on the Internet, of course, but I've yet to find
any which are 100% reliable.

Mark

Nov 19 '05 #2
its a pretty simple list. toString() that returns the local version, there
is an options radix, used to specify the radix used for numberss

full spec :
http://www.ecma-international.org/pu...s/Ecma-262.htm

javascript has the following objects types:

object toString() results
------- ----------------------------
Array does to a toString of all object sand concats the results
Boolean return "true" or "false"
Date returns date in locale format
Function return func def as string
Error return error message
Number return number as string based on radix (default = 10)
String returns string value
Default return "[object objectname]"

the Date object has some additional string functions (none of these take a
parameter, and return the obvious):

toDateString()
toGMTString()
toLocaleDateString()
toLocaleString()
toLocaleTimeString()
toTimeString()
toUTCString()

the Number object has the additional following:

toFixed (factionDigits)
toLocalString()
toPrecision(precision)
most sites write their own formating utilities

-- bruce (sqlwork.com)



"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Does anyone know of a "definitive" source of JavaScript formatting
functions e.g. to format numbers, dates, currencies etc?

There are loads of examples on the Internet, of course, but I've yet to
find any which are 100% reliable.

Mark

Nov 19 '05 #3
"Bruce Barker" <br******************@safeco.com> wrote in message
news:ey****************@TK2MSFTNGP09.phx.gbl...
most sites write their own formating utilities


Yes indeed - I was wondering if anyone had found one which was 100%
efficient, because I haven't...
Nov 19 '05 #4
Mark,

I have personal experience with http://www.mattkruse.com/javascript/date/
for date formatting. It is good.

Eliyahu

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

Does anyone know of a "definitive" source of JavaScript formatting functions e.g. to format numbers, dates, currencies etc?

There are loads of examples on the Internet, of course, but I've yet to find any which are 100% reliable.

Mark

Nov 19 '05 #5
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

Eliyahu,
I have personal experience with http://www.mattkruse.com/javascript/date/
for date formatting. It is good.


This is precisely what I'm talking about! On the surface this looks
excellent, just the way that hundreds of other such examples on the Internet
look excellent.

However, if you pass the strings '15 Sep 2005' or '15 September 2005'
through the isDate() function, it returns false - that's rubbish!

Mark
Nov 19 '05 #6
Mark,

Could be isDate() is not good. I am using it only for formatting the dates
and never had any issues so far.

Eliyahu

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:O7**************@TK2MSFTNGP15.phx.gbl...
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

Eliyahu,
I have personal experience with http://www.mattkruse.com/javascript/date/ for date formatting. It is good.
This is precisely what I'm talking about! On the surface this looks
excellent, just the way that hundreds of other such examples on the

Internet look excellent.

However, if you pass the strings '15 Sep 2005' or '15 September 2005'
through the isDate() function, it returns false - that's rubbish!

Mark

Nov 19 '05 #7
Mark Rae wrote:
I have personal experience with http://www.mattkruse.com/javascript/date/
for date formatting. It is good. This is precisely what I'm talking about! On the surface this looks
excellent, just the way that hundreds of other such examples on the Internet
look excellent.


As the author, I can tell you that this code is used on thousands of
web sites, and it is quite solid ;)
However, if you pass the strings '15 Sep 2005' or '15 September 2005'
through the isDate() function, it returns false - that's rubbish!


The isDate() function takes a date format to validate against, as could
be expected of any isDate() function.

If you enter '15 Sep 2005' or '15 September 2005' with the date format
'dd MMM yyyy' it says true. Just as expected.

Where's the problem?

Matt Kruse
http://www.mattkruse.com/

Nov 19 '05 #8
Wow, here is the author!

Matt, I just take an opportunity to thank you for the code. For me it is
really good, appreciated.

Eliyahu

<ma**@mattkruse.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Mark Rae wrote:
I have personal experience with http://www.mattkruse.com/javascript/date/ for date formatting. It is good.

This is precisely what I'm talking about! On the surface this looks
excellent, just the way that hundreds of other such examples on the Internet look excellent.


As the author, I can tell you that this code is used on thousands of
web sites, and it is quite solid ;)
However, if you pass the strings '15 Sep 2005' or '15 September 2005'
through the isDate() function, it returns false - that's rubbish!


The isDate() function takes a date format to validate against, as could
be expected of any isDate() function.

If you enter '15 Sep 2005' or '15 September 2005' with the date format
'dd MMM yyyy' it says true. Just as expected.

Where's the problem?

Matt Kruse
http://www.mattkruse.com/

Nov 19 '05 #9
<ma**@mattkruse.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Matt,
Where's the problem?


I may be maligning you unfairly. I simply went to the site that Eliyahu
mentioned (http://www.mattkruse.com/javascript/date/), entered the string
'15 Sep 2005' in the Free-Form Date Field text box, and clicked
parseDate() - the message was "Date string does not match any recognized
formats!"

Mark
Nov 19 '05 #10
Mark Rae wrote:
I may be maligning you unfairly. I simply went to the site that Eliyahu
mentioned (http://www.mattkruse.com/javascript/date/), entered the string
'15 Sep 2005' in the Free-Form Date Field text box, and clicked
parseDate() - the message was "Date string does not match any recognized
formats!"
This is true. There are two different things, here:

isDate() requires a date format to validate against. If you specify the
correct date format, isDate will correctly tell you that '15 Sep 2005'
is valid.

parseDate() tries to parse a free-form string into a date object. Since
there are obviously many different possible date formats you can enter,
it checks some common formats. It's meant as a last-resort for figuring
out a date that a user entered into a free-form field. It's always
preferred that a format is required and specified for the user, and
their value is validated against the format.
From the code comments:


// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d MMM d, y MMM d,y y-MMM-d d-MMM-y MMM d
// M/d/y M-d-y M.d.y MMM-d M/d M-d
// d/M/y d-M-y d.M.y d-MMM d/M d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------

The format you're looking for, 'dd MMM yyyy' isn't one of the formats
that are automatically checked, so it will not recognize your date.

You can either use the getDateFromFormat function, which takes a string
and a format, or you can modify the parseDate code to check for more
date formats that you wish to check for. I got most of the common ones,
but perhaps 'dd MMM yyyy' should be included in there also :)

Matt Kruse
http://www.mattkruse.com

Nov 19 '05 #11
<ma**@mattkruse.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...

Matt,

I clearly owe you an apology... :-)
but perhaps 'dd MMM yyyy' should be included in there also :)


Well, that's the format I always try first, for three principal reasons:

1) it's guaranteed to be totally unambiguous as opposed to, say, 03/04/05

2) it's guaranteed to be Y2K compatible

3) it's guaranteed to give the same results against SQL Server, no matter
which culture settings were used when the server was built.

It's also pretty much the de facto default format in the UK...

Mark
Nov 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5346
by: useenmelately | last post by:
Hello, I am working with asp.net 2.0 and have run into a problem with the custom validators. The client validation functions were originally written in vbscript, but as this is not compatible...
22
2287
by: Tony Girgenti | last post by:
Hello. I'm developing and testing a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2 computer. I'm using a web form. Using...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.