正则表达式
规则字符串
匹配内容
/s 匹配空格
/d 匹配任意数字 0-9
/w 匹配任意字母/数字 A-Z a-z 0-9
. 匹配任意符号/数字/字母 A-Z a-z 0-9 任意符号
匹配字符长度
* 任意长度
+ 至少1个
? 0或1个
{n} 必须n个
{n,m} 必须n-m个
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正则表达式</title>
<script src="jquery/jquery-3.6.0.js"></script>
</head>
<body>
<input type="text" id="code" placeholder="正则表达式">
<button id="btn-valid">正则校验</button>
</body>
<script>
// var reg = /^\d{3}\s+\d{3,8}$/ //123 12345678
// var reg = /^\d{3}\-\d{3,8}$/ //123-12345678
// var reg = /^[0-9a-zA-Z\_]$/ //a _ 1
// var reg = /^[0-9a-zA-Z\_\$][0-9a-zA-Z\_\$]{0,19}$/ //0-20个任意0-9a-zA-Z字符
// var reg =/^1(3[0-9]|5[0-9]|7[0-9]|8[0-9]|9[0-9])\d{8}$/ //手机号校验
// var reg = /^[1-9]\d{5}(18|19|20(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])10|20|30|31)\d{3}[0-9Xx]$/
$('#btn-valid').click(function (){
var code = $('#code').val()
if(reg.test(code)){
console.log('字符串合法')
}else {
console.log('字符串不合法')
}
})
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户注册</title>
<script src="jquery/jquery-3.6.0.js"></script>
<script src="bootstrap-3.4.1/bootstrap-3.4.1/dist/js/bootstrap.js"></script>
<link rel="stylesheet" href="bootstrap-3.4.1/bootstrap-3.4.1/dist/css/bootstrap.css">
<script>
// js 或 jq 代码写在html 上面 是百分之百 不安全的
// 写在 html 下面 有可能不安全
// 写在$(function (){})这个回调函数里面百分之百安全
// $(document).ready(function (){}) 和 $(function(){}) 两种写法
$(function (){
function hasError($node,msg){
$node.parent().addClass("has-error")
$node.next().addClass("glyphicon-remove")
$node.next().next().text(msg)
}
function hasWarning($node,msg){
$node.parent().addClass("has-warning")
$node.next().addClass("glyphicon-warning-sign")
$node.next().next().text(msg)
}
function hasSuccess($node,msg){
$node.parent().addClass("has-success")
$node.next().addClass("glyphicon-ok")
$node.next().next().text(msg)
}
function clear($node){
$node.parent().removeClass("has-error")
$node.parent().removeClass("has-success")
$node.parent().removeClass("has-warning")
$node.next().removeClass("glyphicon-remove")
$node.next().removeClass("glyphicon-ok")
$node.next().removeClass("glyphicon-warning-sign")
$node.next().next().text("")
// $node.select()
$node.val('')
}
$('#username').blur(function (){
var username = $('#username').val();
// if (username == null || username ==''){ //等于 if (!username){
if (!username){
hasError($(this),'不能为空')//$node =$(this)
}else {
hasSuccess($(this),'success')
}
}).focus(function (){
clear($(this))
})
$('#password,#confirmPassword').blur(function (){
var reg =/^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/
var currentPassword = $(this).val()
if (currentPassword.length<6){
hasError($(this),'密码不能少于6位')
return;
}
if (!reg.test(currentPassword)){
hasWarning($(this),'密码强度:弱!')
}else{
hasSuccess($(this),'Success!')
}
var password =$('#password').val()
var confirmPassword = $('#confirmPassword').val()
if (password.length >= 6 && confirmPassword.length>=6 ){
if (password === confirmPassword){
if (reg.test(password) && reg.test(confirmPassword)) {
if (!$('#password').hasClass('has-success')) {
hasSuccess($('#password'), 'Success!')
}
if (!$('#confirmPassword').hasClass('has-success')) {
hasSuccess($('#confirmPassword'), 'Success!')
}
}else{
if (!$('#password').hasClass('has-warning')) {
hasWarning($('#password'), '密码强度:弱!')
}
if (!$('#confirmPassword').hasClass('has-warning')){
hasWarning($('#confirmPassword'), '密码强度:弱!')
}
}
}else{
hasError($(this), '两次输入的密码不一致')
}
}
})
.focus(function (){
clear($(this))
})
$('#btn-reset').click(function (){
clear($('#username'))
clear($('#password'))
clear($('#confirmPassword'))
clear($('#email'))
clear($('#id-code'))
$('[name=sex]:first').prop('checked',true)
})
$('#btn-close').click(function (){
console.log('close')
})
$('#btn-submit').click(function (){
console.log('submit')
})
})
</script>
</head>
<body>
<div class="container" style="padding-top: 50px">
<div class="row">
<div class="col-md-15 col-md-offset-15">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="=panel-title">Sign In</h3>
<a href="用户登录.html" class="btn btn-primary" style="background-color: #00ccff">Sign up</a>
</div>
<div class="panel-body">
<form>
<div class="form-group has-feedback">
<label class="control-label" for="username" ><span class="glyphicon glyphicon-user"> </span>
Username <span style="color: #ff0000" class="glyphicon glyphicon-star" ></span></label>
<input type="text" class="form-control" id="username">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<label class="control-label"></label>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="password" > <span class="glyphicon glyphicon-lock"> </span>
Password <span style="color: red">*</span></label>
<input type="text" class="form-control" id="password">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<label class="control-label"></label>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="confirmPassword" ><span class="glyphicon glyphicon-lock"> </span>
ConfirmPassword <span style="color: red" class="glyphicon glyphicon-star" ></span>
</label>
<input type="text" class="form-control" id="confirmPassword">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<label class="control-label"></label>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="email" ><span class="glyphicon glyphicon-envelope"> </span>Email</label>
<input type="email" class="form-control" id="email">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span class="sr-only">(success)</span>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="mobile" ><span class="glyphicon glyphicon-earphone"> </span>Mobile</label>
<input type="text" class="form-control" id="mobile">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span class="sr-only">(success)</span>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="id-code" ><span class="glyphicon glyphicon-user"> </span>IdCode</label>
<input type="text" class="form-control" id="id-code">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<span class="sr-only">(success)</span>
</div>
<div>
<div class="form-group">
<label class="control-label"><span class="glyphicon glyphicon-user"> </span>Sex</label>
</div>
<label class="radio-inline">
<input type="radio" value="男" name="sex" checked>男
</label>
<label class="radio-inline">
<input type="radio" value="女" name="sex" checked>女
</label>
</div>
</form>
</div>
<!-- 把按钮使用栅格 占4格 往右移8格 出现父元素塌陷 给父元素clearfix 清楚浮动即可-->
<div class="panel-footer clearfix">
<div class="col-md-4 col-md-offset-8">
<button class="btn btn-default " id="btn-close">Close</button>
<button class="btn btn-primary" id="btn-submit">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登录</title>
<script src="jquery/jquery-3.6.0.js"></script>
<script src="bootstrap-3.4.1/bootstrap-3.4.1/dist/js/bootstrap.js"></script>
<link rel="stylesheet" href="bootstrap-3.4.1/bootstrap-3.4.1/dist/css/bootstrap.css">
<script>
$(function (){
function hasSuccess($node,msg){
$node.parent().addClass("has-success")
$node.next().addClass('glyphicon-ok')
$node.next().next().text(msg)
}
function hasWarning($node,msg){
$node.parent().addClass("has-warning")
$node.next().addClass('glyphicon-warning')
$node.next().next().text(msg)
}
function hasError($node,msg){
$node.parent().addClass("has-error")
$node.next().addClass('glyphicon-remove')
$node.next().next().text(msg)
}
function clear($node) {
$node.parent().removeClass("has-error")
$node.parent().removeClass("has-success")
$node.next().removeClass("glyphicon-remove")
$node.next().removeClass("glyphicon-ok")
$node.next().removeClass("glyphicon-warning")
$node.next().next().text("")
// $node.select()
$node.val('')
}
$('#username').blur(function (){
var username = $('#username').val();
// if (username == null || username ==''){ //等于 if (!username){
if (!username){
hasError($(this),'不能为空')//$node =$(this)
}else {
hasSuccess($(this),'success')
}
}).focus(function (){
clear($(this))
})
$('#btn-close').click(function (){
console.log('close')
})
$('#btn-submit').click(function (){
console.log('submit')
})
})
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Sign up</h3>
<a href="用户注册.html" class="btn btn-primary" style="background-color: #00ccff">Sign in</a>
</div>
<div class="panel-body">
<form>
<div class="form-group has-feedback">
<label class="control-label" for="username"><span class="glyphicon glyphicon-user"></span>Username
<span style="color: red" >*</span></label>
<input type="text" class="form-control" id="username">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-feedback">
<label class="control-label" for="password"><span class="glyphicon glyphicon-lock"></span>Password
<span style="color: red" >*</span></label>
<input type="password" class="form-control" id="password">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
</form>
</div>
<div>
<div class="panel-footer clearfix">
<div class="col-md-4 col-md-offset-4">
<button class="btn btn-default" id="btn-close">Close</button>
<button class="btn btn-primary" id="btn-submit">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home主页</title>
<script src="jquery/jquery-3.6.0.js"></script>
<script src="bootstrap-3.4.1/bootstrap-3.4.1/dist/js/bootstrap.js"></script>
<link rel="stylesheet" href="bootstrap-3.4.1/bootstrap-3.4.1/dist/css/bootstrap.css">
<script>
$(function (){
$('.carousel').carousel({interval:2000})
})
</script>
<style>
#header{
height: 32px;
font-size: 12px;
background-color: #f2f2f2;
border-bottom: 1px solid #e5e5e5;
}
#abc{
height: 80%;
}
.pro-item{
background-color: whitesmoke;
width: 220px;
padding: 10px 0px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.pro-img{
width:185px
}
.pro-desc{
text-align: center;
width: 150px;
}
.pro-price{
color: red;
font-weight: bold;
font-size: 16px;
}
</style>
</head>
<body style="background-color: #f4f1f1">
<div class="container-fluid">
<!-- Start Header-->
<div class="row" id="header">
<!-- End Header-->
<!-- start Header-->
</div>
</div>
<div class="row" style="background-color: #00ccff">
<div class="container" id="abc">
<div class="row" id="search-bar">
<div class="col-md-2 col-md-offset-2">
<img src="img素材/images/images/fore/WebsiteImage/HomeLogoA.png">
</div>
<div id="carousel-example-generic" class="carousel slide " data-ride="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators ">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
<li data-target="#carousel-example-generic" data-slide-to="3"></li>
<li data-target="#carousel-example-generic" data-slide-to="4"></li>
<li data-target="#carousel-example-generic" data-slide-to="5"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img素材/images/images/fore/WebsiteImage/banner/42.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="img素材/images/images/fore/WebsiteImage/banner/43.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="img素材/images/images/fore/WebsiteImage/banner/44.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="img素材/images/images/fore/WebsiteImage/banner/45.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="img素材/images/images/fore/WebsiteImage/banner/46.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="img素材/images/images/fore/WebsiteImage/banner/47.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
...
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div></div>
<!--End Carousel-->
<!--Start ProductList-->
<div class="row" style="padding: 15px 350px">
<div class="col-md-10 col-md-offset-2" style="border-left: 5px #ff07fe solid">女装/大衣</div>
<div class="col-md-2 col-md-offset-1">
<img src="img素材/images/images/fore/WebsiteImage/show/1.jpg" width="235" alt="1.jpg">
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-1 pro-item">
<img class="pro-img" src="img素材/images/images/item/productSinglePicture/e95d4a9d-ebe9-4f12-975b-2e94e98aa2ef.jpg" width="235" alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-1 pro-item">
<img src="img素材/images/images/item/productSinglePicture/f1e55cd1-a044-4c25-a2a5-cbb479cc6857.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/46d2ce8a-b4ab-4f70-bc95-3f1e9e0c7623.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/6938846f-ae3c-4265-9d8c-f2da4738dc43.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/da1f9f23-346b-4c21-917c-1746932574be.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/da1f9f23-346b-4c21-917c-1746932574be.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/da1f9f23-346b-4c21-917c-1746932574be.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
<div class="col-md-3 pro-item">
<img src="img素材/images/images/item/productSinglePicture/da1f9f23-346b-4c21-917c-1746932574be.jpg" width="190"
alt="1.jpg">
<p class="pro-desc">2018春季新款学生卫衣女</p>
<p class="pro-price">¥79.5</p>
</div>
</div>
</div>
</div>
</body>
</html>
本文介绍了正则表达式在用户注册和登录时的应用,讲解了如何使用规则字符串进行内容匹配,如/s匹配空格,/d匹配数字,/w匹配字母和数字,以及点号"."匹配任意符号、数字和字母。同时,探讨了匹配字符长度的规则,如*、+、?、{n}和{n,m}等,这些规则对于确保输入的正确性和安全性至关重要。

1282

被折叠的 条评论
为什么被折叠?



