Regular expression date control with jQuery
How to check date format with regular expression in input text?
开发者_开发知识库Format: 20.04.1986
I'd use Datejs or some other validation library as they've been tested and used for awhile, but if you just want some raw regex, here's what I came up with quickly. This regex will work, but it won't check that the year is over a certain reasonable date; it will only check that it's four numbers long.
if(date.search(/([1-9]\d)\.((0[1-9])|(1[0-2]))\.\d{4}/) > -1){
//do stuff when date is valid
}else{
//do stuff when date is not valid
}
Try:
function call()
{
if ($("#date").val().search((/^\d{2}[.]\d{2}[.]\d{4}$/))>-1) {
$("#date").css('background-color', '#FF0000');
}
else {
alert("good");
}
}
精彩评论