这是我的代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="datetime.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id$=txtDate]").datepicker({});
$("#txtDate").blur(function () {
val = $(this).val();
val1 = Date.parse(val);
if (isNaN(val1) == true && val !== '') {
alert('Date is not valid');
$("#txtDate").val($.datepicker.formatDate("mm-dd-yy", new Date()));
}
else {
console.log(val1);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</form>
</body>
</html>
在上面的代码中,我有一个文本框,当用户单击文本框时,它会打开日期选择器并选择日期。如果用户手动输入日期如何使用 jquery 进行验证。 例如:- 01011 --> 这次显示无效日期警报 例如:- 01-01-2016
最佳答案
您可能希望更改为专门用于输入日期的type="date"
。
关于javascript - 如何使用 JQuery 在 asp.net 的 TextBox 中输入日期时进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38605666/