0
如果我想驗證文本框中的日期像11月jul-2009使用JavaScript作爲每cluture那麼我該怎麼辦懇請告訴我,如果任何機構知道....?Javascript日期驗證的Asp.net
我使用這個功能....
function isDate(obj)
{
var retVal = false;
var dteDate;
/* Check for mm/dd/yyy format */
obj1 = obj.split("/");
obj1[0] = parseInt(obj1[0], 10)-1; //for javascript 0=>January!
obj1[1] = parseInt(obj1[1], 10);
obj1[2] = parseInt(obj1[2], 10);
dteDate=new Date(obj1[2], obj1[0], obj1[1]);
retVal = ((obj1[1]==dteDate.getDate()) && (obj1[0]==dteDate.getMonth()) && (obj1[2]==dteDate.getFullYear()));
/* Check for dd-mmm-yyy format */
if(retVal == false)
{
obj1 = obj.split("-");
if (obj1.length<3) return false;
var month = isDate.months[obj1[1].toLowerCase()];
if (typeof month != "number") return false;
obj1[0] = parseInt(obj1[0], 10);
obj1[1] = parseInt(month, 10)-1; //for javascript 0=>January!
obj1[2] = parseInt(obj1[2], 10);
dteDate=new Date(obj1[2], obj1[1], obj1[0]);
retVal=(obj1[0]==dteDate.getDate()) && (obj1[1]==dteDate.getMonth()) && (obj1[2]==dteDate.getFullYear());
}
return retVal;
}
isDate.months = {
jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5,
jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11
};
在abouve功能我如何使用日期驗證按照Currrent文化就像我們使用 FR-FR那麼它給錯誤來驗證
... 。:( 所以Plesa告訴我另一種方式來sloved這個問題....
其他可能的重複:<?http://stackoverflow.com /問題/ 661117/JavaScript的-regexp-validating-date-problem>,, –
Cerebrus
2009-07-17 09:36:49