日期:2014-05-16 浏览次数:20426 次
<script language="javascript">
function check(){
var a = /^(\d{4})-(\d{2})-(\d{2})$/
if (!a.test(document.getElementById("TextBox1").value)) {
alert("日期格式不正确!")
return false
}
else
return true
}
</script>
^(\d{4})-(\d{1,2})-(\d{1,2})$
var isValidDate = function (value, userFormat) {
var
userFormat = userFormat
------解决方案--------------------
'mm/dd/yyyy', // default format
delimiter = /[^mdy]/.exec(userFormat)[0],
theFormat = userFormat.split(delimiter),
theDate = value.split(delimiter),
isDate = function (date, format) {
var m, d, y
for (var i = 0, len = format.length; i < len; i++) {
if (/m/.test(format[i])) m = date[i]
if (/d/.test(format[i])) d = date[i]
if (/y/.test(format[i])) y = date[i]
}
return (
m > 0 && m < 13 &&
y && y.length === 4 &&
d > 0 && d <= (new Date(y, m, 0)).getDate()