【发布时间】:2009-07-17 09:33:53
【问题描述】:
如果我想使用 javascript 作为 Per cluture 来验证文本框中的日期,例如 2009 年 7 月 11 日,那么我该如何告诉我是否有人知道......?
我正在使用这个功能....
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
};
在上面的函数中,我如何按照我们正在使用的当前文化使用日期验证 fr-FR 然后它给出错误来验证 ....:( 所以请告诉我还有什么方法可以解决这个问题......?
【问题讨论】:
-
其他可能的重复项:stackoverflow.com/questions/661117/…>、stackoverflow.com/questions/777725/…>、stackoverflow.com/questions/939802/…>
标签: javascript