jQuery表单正则校验(邮箱、手机号、身份证)
→邮箱校验需输入@.符号 例如:@Gmail.com
→手机号校验需开头以1开头的11位纯数字
→身份证校验需18位纯数字
★效果图如下
→ NO : 提交按钮
→ OFF :清空输入框内容
★CSS
-
<style>
-
ul li{
-
list-style-type: none;
-
height: 50px;
-
}
-
form ul:last-child input{
-
background-image: -webkit-linear-gradient(darksalmon,#527590);
-
-webkit-background-clip: text;
-
-webkit-text-fill-color: transparent;
-
border: none;
-
}
-
form ul:first-child input{
-
background-image: -webkit-linear-gradient(darksalmon,#527590);
-
-webkit-background-clip: text;
-
-webkit-text-fill-color: transparent;
-
border-radius: 10px;
-
border: 1px #527590 solid;
-
}
-
span{
-
background-image: -webkit-linear-gradient(darksalmon,#527590);
-
-webkit-background-clip: text;
-
-webkit-text-fill-color: transparent;
-
font-size: 13px;
-
}
-
</style>
★HTML
-
<form>
-
<ul class="ul_one">
-
<li>
-
<input type="text" placeholder="邮箱校验" id="first">
-
<span id="checkfirst"> </span>
-
</li>
-
<li>
-
<input type="text" placeholder="手机号校验" id="second">
-
<span id="checksecond"> </span>
-
</li>
-
<li>
-
<input type="text" placeholder="身份证号校验" id="third">
-
<span id="checkthird"> </span>
-
</li>
-
</ul>
-
<ul>
-
<li>
-
<input type="submit" value="NO">
-
</li>
-
<li>
-
<input type="button" value="OFF" id="OFF">
-
</li>
-
</ul>
-
</form>
★jQurey
-
<script>
-
$(function () {
-
$("#first").blur(checkfirst);
-
$("#second").blur(checksecond);
-
$("#third").blur(checkthird);
-
$('#OFF').click(function () {
-
$('.ul_one input').val("")
-
})
-
$("form").submit(function () {
-
let flag = true;
-
if (!checkfirst()){
-
flag = false;
-
}
-
if (!checksecond()){
-
flag = false;
-
}
-
if (!checkthird()){
-
flag = false;
-
}return flag;
-
});
-
function checkfirst() {
-
let first = $("#first");
-
let checkfirst = $("#checkfirst");
-
let one =/^[a-zA-Z0-9_-] @[a-zA-Z0-9_-] (\.[a-zA-Z0-9_-] ) $/;
-
checkfirst.html("");
-
if (first.val() === ""){checkfirst.html("非空");
-
return false;
-
}
-
if (one.test(first.val()) === false){
-
checkfirst.html("邮箱格式错误");
-
return false;
-
}
-
return true;
-
}
-
function checksecond() {
-
let second = $("#second");
-
let checksecond = $("#checksecond");
-
checksecond.html("");
-
let two = /^1\d{10}$/;
-
if (second.val() === ""){
-
checksecond.html("非空");
-
return false;
-
}
-
if (two.test(second.val()) === false){
-
checksecond.html("手机号格式错误");
-
return false;
-
}
-
return true;
-
}
-
function checkthird(){
-
let third = $("#third");
-
let checkthird = $("#checkthird");
-
let three =/^\d{18}$/;
-
checkthird.html("");
-
if (third.val() === ""){
-
checkthird.html("非空");
-
return false;
-
}
-
if (three.test(third.val()) === false){
-
checkthird.html("身份证号格式错误");
-
return false;
-
}
-
return true;
-
}
-
})
-
</script>
Ps : 不要忘记引入jQuery
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhiajbfi
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22 -
excel打印预览压线压字怎么办
PHP中文网 06-22