Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy question about Dates

Status
Not open for further replies.

JayBuys

Programmer
Jun 18, 2001
17
US
It's been a while since I've used JavaScript since I write most of my stuff now in ASP with VBScript. However, I need to do something in JavaScript and I need a little help.

VBScript has a function called 'IsDate' which will return a boolean value indicating whether an expression can be converted to a valid date. This is great for validating form input before entering the information into a database, avoiding type mismatch errors.

Does JavaScript have an equivalent function? I haven't been able to find one in a quick search through any of my books. I figured it'd be easiest to just ask the experts. If there is a similar function can you tell me it's name or if there isn't does anyone have a simple date validation script?

Thanks in advance for your help.
 
hi

what format do you mean? if you would say what format would you accept for your database input, i'm shure someone here would write a regular expression to validate it

as for a special function - it was long time ago when i watched the documentations last time, so, can't tell you if there is such a function (at least i don't remember one) Victor
 
YYYY-MM-DD is the format it would need to be in
 
if those values are digits, here is a function:

function validate(obj){
//the expression:
var re=/^\d{4}\-\d{2}\-\d{2}$/
var str=obj.value
if (!str) {alert("enter something");obj.focus(); return false}
if (!str.match(re)){
alert("wrong date format, YYYY-MM-DD needed");
obj.focus();obj.select();return false;
}
}

& how to call it (one of the ways):
<input type=text name=thename onchange=&quot;validate(this)&quot;> Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top