帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» jQuery基于正则表达式的表单验证功能示例
jQuery基于正则表达式的表单验证功能示例
浏览:633次
-
评论:0次
-
发布时间:2017-03-09
Html
Css
Js
demo
输入字符
输入正确的数字
输入正确的电话
确移动电话
邮箱地址
inernet地址
.over { font-size: large; font-style: italic; } .out { font-size: small; }
function validata() { if ($("#username").val() == "") { alert("请输入名字"); return false; } if ($("#password").val() == "") { alert("请输入密码"); return false; } if ($("#telephone").val() == "") { alert("请输入电话号码"); } if ($("#email").val() == "") { $("#email").val("shuangping@163.com"); } } function isInteger(obj) { reg = /^[-+]?\d+$/; if (!reg.test(obj)) { $("#test").html("
Please input correct figures
"); } else { $("#test").html(""); } } function isEmail(obj) { reg = /^\w{3,}@\w+(\.\w+)+$/; if (!reg.test(obj)) { $("#test").html("
请输入正确的邮箱地址
"); } else { $("#test").html(""); } } function isString(obj) { reg = /^[a-z,A-Z]+$/; if (!reg.test(obj)) { $("#test").html("
只能输入字符
"); } else { $("#test").html(""); } } function isTelephone(obj) { reg = /^(\d{3,4}\-)?[1-9]\d{6,7}$/; if (!reg.test(obj)) { $("#test").html("
请输入正确的电话号码!
"); } else { $("#test").html(""); } } function isMobile(obj) { reg = /^(\+\d{2,3}\-)?\d{11}$/; if (!reg.test(obj)) { $("#test").html("请输入正确移动电话"); } else { $("#test").html(""); } } function isUri(obj) { reg = /^http:\/\/[a-zA-Z0-9]+\.[a-zA-Z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^\"\"])*$/; if (!reg.test(obj)) { $("#test").html($("#uri").val() + "请输入正确的inernet地址"); } else { $("#test").html(""); } } //document加载完毕执行 $(document).ready(function() { // do something here //隔行换色功能 $("p").each(function(i) { this.style.color = ['red', 'green', 'blue', 'black'][i % 2] }); //eq(2)获取$("p")集合的第3个元素 $("p").eq(2).click(function() { $("#display").css("color", "blue") }); //所有test中的p都附加了样式"over"。 $("#test>p").addClass("over"); //test中的最后一个p附加了样式"out"。 $("#test p:last").addClass("out"); //选择同级元素还没看懂 //$('#faq').find('dd').hide().end().find('dt').click(function() //选择父级元素 $("a").hover(function() { $(this).parents("p").addClass("out") }, function() { $(this).parents("p").removeClass("out") }) //hover鼠标悬停效果,toggle每次点击时切换要调用的函数 , //trigger(eventtype): 在每一个匹配的元素上触发某类事件, //bind(eventtype,fn),unbind(eventtype): 事件的绑定与反绑定从每一个匹配的元素中(添加)删除绑定的事件。 //方法的连写 $("#display").hover(function() { $(this).addClass("over"); }, function() { $(this).removeClass("over"); }).click(function() { alert($("#display").text()) }); });
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>jQuery基于正则表达式的表单验证功能示例-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:jQuery基于正则表达式的表单验证功能包括针对字符串、邮件、网址、电话等常见正则验证操作技巧需要的朋友可以参考下
jQuery实现简易的输入框字数计数功能示例
jQuery实现拖动效果
讨论这个常用代码(0)
回答他人问题或分享心得会奖励牛币
〒_〒 居然一个评论都没有……
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
633
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值