如何使用jquery验证日期字段? [英] how to validate date field using jquery?

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

问题描述

我在表单中添加了日历..如果用户没有选择日期字段,我需要显示错误信息。

解决方案

这是一个检查有效日期的函数格式如下所述: -



<前lang =Javascript> 功能 IsValidDate(dtValue)
{
var dtRegex = new RegExp (/ \\\ { 1 2 } [\ / - ] \d { 1 2 } [\ / - ] \d { 4 } \b /);
return dtRegex.test(dtValue);
}







要在任何日期使用此方法,下面的文本字段是代码示例: -



 


function (){


' 。errorDiv' ).hide();

i added calender in the form..i need to display error message if user not selecting the date field.

解决方案

Here is a function to check valid date format as mentioned below :-

function IsValidDate(dtValue)
{
    var dtRegex = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d  {4}\b/);
    return dtRegex.test(dtValue);
}




To Use this method on any date text field below is the code example :-


(function() {


('.errorDiv').hide();


这篇关于如何使用jquery验证日期字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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