使用jquery/Javascript进行验证 [英] Validation using jquery/Javascript

查看:52
本文介绍了使用jquery/Javascript进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个html表单,用户需要在其中输入文本框中的出生日期.
我想验证一下,并且只允许他/她的年龄在18岁以上.
如果没有,那么系统应该显示他无法登录的消息...

我想使用Jquery/Javascript来做.

我该怎么办?

谢谢

hi all,

I have a html form in which the user needs to enter his date of birth in a textbox.
I want to validate it and allow him only if his/her age is above 18 years.
if not then system should display message that he cant login...

i want to do it using Jquery/Javascript.

what should i do ?

Thanks

推荐答案

看看下面的链接.

http://dev-tips.com/featured/how-to-用jQuery验证出生日期

别忘了Google是全球许多开发人员的朋友.
Have a look at below link.

http://dev-tips.com/featured/how-to-validate-date-of-birth-with-jquery

And don''t forget Google is a friend of many Developers across the Globe.




我尝试了一些JavaScript代码来满足您的要求,请尝试一次
Hi,

I tried some javascript code for your requirement try this once
<input type ="text" id="txtdate" />{dd-mm-yyyy}
   <input type ="button" value ="check" onclick ="delval()" />



而javascript函数是



And javascript function is

<script language ="javascript" >
    function delval() {
        var num = document.getElementById("txtdate").value;
        var pattern = /(^[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]


)/; 如果(数字搜索(模式)== -1) alert(" ); 其他 { var pd = 日期(); var bd = 日期(); var df = num.split(' -'); bd.setFullYear(df [ 2 ],df [ 0 ],df [ 6570 ); 如果(bd< pd){ alert(" ); } 其他 { alert(" ); } } } </script>
)/; if (num.search(pattern) == -1) alert("Invalid Format"); else { var pd = new Date(); var bd = new Date(); var df = num.split('-'); bd.setFullYear(df[2], df[0], df[1]); bd.setDate(bd.getDate() + 6570); if (bd < pd) { alert("Valid"); } else { alert("Invalid Age"); } } } </script>



希望它也为您服务

最好的



I hope its work for you also

All the Best


这篇关于使用jquery/Javascript进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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