『前端学习实例』 表单验证-注册(Javascript正则表达式)

本文通过一个实例介绍了如何在前端实现用户注册表单的验证,利用JavaScript的正则表达式对用户名、手机号、身份证号和电子邮箱进行有效性校验。在用户交互过程中,表单会根据输入内容实时显示验证状态,包括密码强度的三级提示。详细代码及效果展示已附带。
摘要由CSDN通过智能技术生成

参考文档:JavaScript 教程 W3school




功能需求

  • 实现用户注册界面。(自定义CSS样式)
  • 实现表单验证。(使用Javascript正则表达式)



结果展示

  • 默认状态:
    在这里插入图片描述
  • 输入提交:

在这里插入图片描述

  • 功能:用户名 / 手机号 / 身份证号 / 电子邮箱 校验
  1. 默认状态(点击)
    在这里插入图片描述
  2. 不符合要求(鼠标移出)
    在这里插入图片描述
  3. 符合要求(鼠标移出)
    在这里插入图片描述
  • 功能:密码强度校验
  1. 弱密码
    在这里插入图片描述

  2. 中密码
    在这里插入图片描述

  3. 强密码
    在这里插入图片描述



源代码



index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
</head>

<body>


<style type="text/css">
  /*基本布局容器*/
  div{
   
    position: absolute;
    width: 100%;
    height: 100%;
    float: left;
  }
  header{
   
    width: 100%;
    height: 20%;
    border-bottom: 1px solid #ccc;
  }
  header>h1{
   
    width: 100%;
    height: 50%;
    margin: unset;
    padding: unset;
    font-size: 60px;
    text-align: center;
  }
  header>h1>a{
   
    color: #b92c28;
  }
  header>a{
   
    position: absolute; /*绝对布局:居右*/
    top: 80px;
    right: 10px;
  }
  header>a>b{
   
    color: red;
  }
  section{
   
    width: 70%;
    height: 70%;
    margin-left: 32%;
  }
  footer{
   
    width: 100%;
    height: 10%;
    border-top: 1px solid #ccc;
    padding-top: 10px;
    color: #ccc;
    text-align: center;
  }
  /*表格*/
  table{
   
    width: 100%;
    height: 100%;
  }
  .info{
   
    width: 20%;
    text-align: right;
  }
  .input{
   
    width: 20%;
  }
  .warning{
    /*默认透明:不显示*/
    width: 60%;
    color: transparent;
  }
  .submit{
   
    width: 80%;
    height: 70%;
    border-radius: 10px;
    border-color: transparent;
    outline: 0;
    color: white;
    font-size: large;
    background-color: #d9534f;
  }
  /*密码校验框*/
  .plex{
   
    position: absolute;
    width: 50px;
    height: 25px;
    margin-top: -10px;
    border-radius: 5px;
    color: black;
    text-align: center;
  }
  /*提交按钮的样式切换*/
 .submitCurrent:hover{
   
    background-color: #ff534f;
  }
  .submitOn
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大熊软糖M

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值