简体   繁体   English

如何使用Jquery.ui.datepicker.css验证带有已过期文本框日期的出生日期

[英]How to validate a date of birth with a date of deceased textboxes using Jquery.ui.datepicker.css

I have a text box that I believe is referencing Jquery.ui.datepicker.css via CssClass? 我有一个文本框,我相信它是通过CssClass引用Jquery.ui.datepicker.css的? :

Textbox 1- Date of birth (where all the validation takes place): 文本框1-出生日期(所有验证均在此处进行):

<asp:TextBox runat="server" ID="txtDOB" CssClass="small date"></asp:TextBox>

Textbox 2- Date of deceased (where data needs to be pulled from for validation to take place): 文本框2-死亡日期(需要从中提取数据以进行验证):

<asp:TextBox runat="server" ID="txtDOD" CssClass="small date"></asp:TextBox>

I'm unfamiliar with jquery but have been trying to program against these two textboxes using C# is this possible? 我不熟悉jquery,但是一直试图使用C#对这两个文本框进行编程,这可能吗?

I'm also unfamiliar with this class jquery.ui.datepicker.css where does it come from? 我也不熟悉此类jquery.ui.datepicker.css,它来自哪里? how is it referenced exactly? 究竟如何引用? and why is this chosen over your typical asp.net control? 为什么选择了典型的asp.net控件?

If not how can I write jquery expressions (would I need regular expressions?) that will accomplish the requirements? 如果不是,我该如何写能满足要求的jquery表达式(我需要正则表达式吗?)。

I am trying to accomplish meeting these requirements: It cannot be a future date, and must be less than the date deceased and must be at least 18 years ago. 我正在努力满足以下要求:它不能是将来的日期,并且必须小于已故的日期,并且必须至少是18年前。

Thank you for any guidance you may have to offer. 感谢您提供的任何指导。

jQuery UI Date Picker just adds a date picker to a text box. jQuery UI Date Picker只是将日期选择添加到文本框中。 When you click in the text box, a little calendar appears and you can pick the date you want. 当您在文本框中单击时,会出现一个小日历,您可以选择所需的日期。 It makes it easier than typing the date in in some cases. 在某些情况下,它比键入日期更容易。 However, it's probably irrelevant to your question. 但是,这可能与您的问题无关。

You need to validate the data on the server side to make sure you don't get bad data, but it's a good idea to also validate on the client side to avoid a round trip to the server. 您需要在服务器端验证数据以确保您不会收到错误的数据,但是最好在客户端进行验证以避免往返服务器。 What you need to do (on both server and client) is... 您需要做的(在服务器和客户端上)是...

  1. Get the value of the date of birth control 获取节育日期的值
  2. Get the value of the date of deceased control 获取已故控制日期的值
  3. Compare the values 比较值
  4. If they don't make sense, provide an error message to the user telling them to correct the problem. 如果它们没有意义,请向用户提供一条错误消息,告诉他们纠正问题。

Server side example: 服务器端示例:

DateTime dob=DateTime.Parse(txtDOB.Text); //consider using an overloaded method to account for different date formats.
DateTime dod=DateTime.Parse(txtDOD.Text); //consider using an overloaded method to account for different date formats.
if(dob>dod)
{
    //provide error message to the client
}

Ideally, this client side logic should happen in your model layer and return some sort of validation summary object to the UI layer, which the UI layer is then responsible for figuring out how to display it to the client. 理想情况下,此客户端逻辑应在您的模型层中发生,并将某种验证摘要对象返回给UI层,然后由UI层负责确定如何将其显示给客户端。

I'll leave the client side example to others. 我将把客户端示例留给其他人。 Note that you'll want to set the ClientIdMode to static so that you get the correct ID's in your controls. 请注意,您需要将ClientIdMode设置为static,以便在控件中获得正确的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM