两个日期的验证问题 [英] validation problem in two date

查看:81
本文介绍了两个日期的验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi friends
i have to text box fist is birth date and second is join date and my problem is how to validate difference between 20 year birth date and join date pls help me

and it is possible to validate to validation control

推荐答案

HI Rashmikants Patel,



你可以使用asp比较验证器来实现这个目的。



http://www.w3schools.com/aspnet/control_comparevalidator.asp [ ^ ]







http://msdn.microsoft.com/en-us/library/db330ayw(v = vs.71).aspx [ ^ ]



Hope这将有所帮助..
HI Rashmikants Patel,

You can use asp Compare Validator for this purpose.

http://www.w3schools.com/aspnet/control_comparevalidator.asp[^]

OR

http://msdn.microsoft.com/en-us/library/db330ayw(v=vs.71).aspx[^]

Hope It will help..


well dude ..例如,如果您有两个文本框输入出生日期& 加入日期和你

希望用户输入出生日期,该日期应该早于加入日期。

I.e.用户出生于1989年12月12日,他于2013年5月12日加入您的办公室...所以你可以使用

比较验证器来做到这一点。



请参阅下面的代码,这可能有助于您澄清我的意思。







well dude.. for example if you have two textboxes to enter "Date of Birth" & "Date of Joining" and you
want the user to enter the date of birth which should have to be the earlier than Date of Joining.
I.e. user was born on 12 feb 1989 and he joined your office etc on 12th may 2013... so you can use
compare validators to do this.

see the code below which might help you to clarify what i meant to say.



<asp:comparevalidator id="Validator1" runat="server" Display = "None" ControlToCompare="txtDateofBirth" ControlToValidate="txtDateofJoining" ErrorMessage="Date of Birth must be before Date of Joining." Operator="GreaterThan" Type="Date" ></asp:comparevalidator> 




上面的代码验证器中的
将检查加入日期与DOB的值,并显示错误消息

如果用户输入截至2013年的出生日期&加入日期为1989年。



问候。



in the above line of code validator will check the value of joining date with DOB and will show the error message
if user enters the date of birth as of 2013 & date of joining as of 1989.

Regards.


你可以将你的标记作为这样的东西



You can have your markup as something like this

<asp:textbox id="startDate" runat="server" xmlns:asp="#unknown"></asp:textbox>
       <asp:textbox id="endDate" runat="server" xmlns:asp="#unknown"></asp:textbox>
       <asp:customvalidator id="cv" runat="server" validationgroup="vg" clientvalidationfunction="validateYears" errormessage="invalid date" display="None" xmlns:asp="#unknown"></asp:customvalidator>
       <asp:button id="btn" runat="server" text="Click" validationgroup="vg" xmlns:asp="#unknown" />
       <asp:validationsummary id="vs" runat="server" validationgroup="vg" showmessagebox="true" showsummary="false" xmlns:asp="#unknown" />





并添加一个js验证方法





and add a js validation method

function validateYears(source, args) {
            startYear = new Date(document.getElementById("startDate").value);
            endYear = new Date(document.getElementById("endDate").value);
            alert(endYear.getFullYear() - startYear.getFullYear() >= 20);
            args.IsValid = endYear.getFullYear() - startYear.getFullYear() >= 20;            
        }





此处的功能获得多年的差异并验证差异为20年,您可能还想考虑几个月或几天的差异。



但是,我不建议使用日期文本框,因为用户可能会使用多种方式输入日期



the function here gets the difference in years and validates for a difference of 20 years, you might also want to consider difference in months or days.

However, i would not recommed using text boxes for dates as users may use multiple ways to enter a date


这篇关于两个日期的验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆