do we have isDate in Jquerry? that returns true if the input is a date else false?
Depending on how you're trying to implement this you can use the validate plugin with the date option set
There's no built-in date functionality in jQuery core...and it doesn't really do anything directly to help with dates, so there aren't many libraries on top of it (unless they're date pickers, etc). There are several JavaScript date libraries available though, to make working with them just a bit easier.
I can't answer for sure what's best...it depends how they're entering it and what culture you're dealing with, keep in mind that different cultures are used to seeing their dates in different format, as a quick example, MM/DD/YYYY
vs YYYY/MM/DD
(or dozens of others).
chk this out :
http://docs.jquery.com/Plugins/Validation/Methods/date
http://stackoverflow.com/questions/511439/custom-date-format-with-jquery-validation-plugin
The best way to get user date input is a date picker that only provides valid dates. It can be done with a string, but you are liable to rile your users by demanding they use your chosen format.
You need to specify in your validator if dates precede months.
This uses a second argument to enforce the order. With no second argument it uses the computer's default order.
// computer default date format order:
Date.ddmm= (function(){
return Date.parse('2/6/2009')> Date.parse('6/2/2009');
})()
allow month names as well as digits: '21 Jan, 2000' or 'October 21,1975'
function validay(str, order){
if(order== undefined) order= Date.ddmm? 0: 1;
var day, month, D= Date.parse(str);
if(D){
str= str.split(/\W+/);
// check for a month name first:
if(/\D/.test(str[0])) day= str[1];
else if (/\D/.test(str[1])) day= str[0];
else{
day= str[order];
month= order? 0: 1;
month= parseInt(str[month], 10) || 13;
}
try{
D= new Date(D);
if(D.getDate()== parseInt(day, 10)){
if(!month || D.getMonth()== month-1) return D;
}
}
catch(er){}
}
return false;
}