正则表达式完成验证

被迫营业的第7天

任务内容:登录页面
   要求:
1. 使用正则表达式验证邮箱
2. 密码长度至少为6位且为字母与数字的组合


展示:


html代码:

<!DOCTYPE html>
<html lang="Cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页</title>
    <link rel="stylesheet" href="./css/Login.css">
</head>
<body>
    <div id="body">
        <form id="form" action="" autocomplete="off">
            <div id="login">
                <b>立即登录</b>
                <span>邮箱</span>
                <input name="email" type="email">
                <span>密码</span>
                <input name="passwd" placeholder="密码长度至少6位" type="password">
                <a href="">忘记密码?</a>
                <div id="btn">
                    <button type="button" onclick="login()">登录</button>
                    <button type="button" onclick="sign()">注册</button>
                </div>
            </div>
        </form>
    </div>
    <script src="./js/Login.js"></script>
</body>
</html>

css代码:

body{
    background-image: url("../img/bg04.jpeg");
    background-repeat: no-repeat;
    margin: 0px;
    padding: 0px;
    background-size: 100% 100%;
    height: 100vh;
}
#body{
    height: 60vh;
    width: 60vh;
    background-color: #fff;
    opacity: 0.8;
    margin: 0px auto;
    position: relative;
    top: 20vh;
    border-radius: 50%;
    box-shadow: 0px 0px 10px #fff;
    animation: overturn 1s linear 1s 1 normal none;
}
@keyframes overturn {
    0%{
        transform: rotateY(0deg);
    }
    50%{
        transform: rotateY(180deg);
    }
    100%{
        transform: rotateY(0deg);
    }
}
#login{
    width: 40vh;
    height: 40vh;
    margin: 0px 10vh;
    position: relative;
    top: 10vh;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    color: #182728;
}
#login > *:not(input){
    flex: 1;
}
#login > b{
    font-size: 20px;
    margin-bottom: 1em;
}
#login > input{
    padding: 0px;
    border-width: 0px;
    outline: none;
    border-bottom: 2px solid #1A292A;
    text-align: center;
    margin-bottom: 1em;
    opacity: 0.8;
    background-color: #fff;
}
#login > a{
    color: #905352;
    font-size: 12px;
}
#btn > button{
    color: #fff;
    background-color: #F88B1C;
    border-radius: 1em;
    padding: 0.25em 1.8em;
    border-width: 0px;
    box-shadow: 2px 2px 2px #8F676C;
}

js代码:

function login(){
    var email=document.getElementsByName('email')[0].value;
    var passwd=document.getElementsByName('passwd')[0].value;
    if(!(/^\d+@[a-zA-Z]+.[a-zA-Z]{2,}$/i.test(email))){
        alert('邮箱地址有问题哦!');
        return;
    }
    if(passwd.length<6){
        alert('密码长度至少6位!');
    }
    else{
        window.location.replace('Flickr.html');
    }
}

function sign(){
    window.location.href='Sign.html';
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值