使用customeValidator确认日期必须大于加入日期 [英] Confirm Date must be greater than Join Date using customeValidator

查看:77
本文介绍了使用customeValidator确认日期必须大于加入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数validate_date(源,参数){
             var  joinDate = document.getElementById(' <%= txt_dateofjoin.ClientID%>').;
             var  confDate = document.getElementById(' <%= txt_confirmationdate.ClientID%>'). var  dt =  Date(joinDate);
             var  dt2 =  Date(confDate);
             var  myDate = dt.format(" );
             var  myDate2 = dt2.format(" );
            如果(myDate <  myDate2)
                args.IsValid =  true ;
            其他
                args.IsValid =  false ;
        } 


该代码不起作用.我知道"dt.format()函数"存在问题,但现在如何验证两个日期.

解决方案

您发布的信息很少,我正在发布我最可能的猜测

 如果(myDate< myDate2)
                args.IsValid =  true ;
            其他
                args.IsValid =  false ; 



加入日期应小于确认日期.只有在这种情况下,.IsValid为true

注意:可以使用asp.net中的CompareValidator来代替javascript.给定标签

 <   asp:CompareValidator       ID   ="  CompareValidator1"  runat   服务器" 
    ErrorMessage   =" 确认日期必须大于加入日期."  ControlToCompare   ="  
 
    ControlToValidate   ="  TextBoxConfirmDate"  ValueToCompare    TextBoxJoinDate" 
   操作员  =" 大于"    类型  日期"  ValidationGroup   ="  >>  <  /asp:CompareValidator  >  


为什么要格式化和比较?两者都是日期.因此,您无需在进行比较之前进行格式化

试试这个.

函数validate_date(来源,参数){
如果(Date.Parse(document.getElementById(' < ;%= txt_dateofjoin.ClientID%>').value< Date.Parse(document.getElementById(' <%= txt_confirmationdate.ClientID%>').)
args.IsValid =  true ;
其他
args.IsValid =  false ; 


function validate_date(source, args) {
            var joinDate = document.getElementById('<%=txt_dateofjoin.ClientID %>').value;
            var confDate = document.getElementById('<%=txt_confirmationdate.ClientID %>').value;

            var dt = new Date(joinDate);
            var dt2 = new Date(confDate);
            var myDate = dt.format("dd-mm-yyyy");
            var myDate2 = dt2.format("dd-mm-yyyy");
            if (myDate < myDate2)
                args.IsValid = true;
            else
                args.IsValid = false;
        }


this code is not working. There are problem with "dt.format() function" I know it but how can I validate two dates now.

解决方案

With the very less information you have posted , I am posting my most probable guess

if (myDate < myDate2)
                args.IsValid = true;
            else
                args.IsValid = false;



Date of join should be less than the confirmation date. Only in that case the .IsValid is true

NOTE: Instead of using javascript, you can use the CompareValidator in asp.net


Alternative way to fullfill your rquirement is Use CompareValidator in following way...Make appropriate changes in value of properties in given tag

<asp:CompareValidator  ID="CompareValidator1" runat="server"

 ErrorMessage="Confirm Date must be greater than Joining Date." ControlToCompare="TextBoxConfirmDate"

 ControlToValidate="TextBoxConfirmDate" ValueToCompare="TextBoxJoinDate"

 Operator="GreaterThan" Type="Date" ValidationGroup="GroupName"></asp:CompareValidator>


Why do you want to format and compare? Both are dates. So you no need to format before doing compare

try this.

function validate_date(source, args) {
if(Date.Parse(document.getElementById('<%=txt_dateofjoin.ClientID %>').value<Date.Parse(document.getElementById('<%=txt_confirmationdate.ClientID %>').value)
args.IsValid=true;
else
args.IsValid=false;


这篇关于使用customeValidator确认日期必须大于加入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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