background: url("img/register_bg.png") no-repeat center;
border: 8px solid #EEEEEE;
.rg_left > p:first-child{
.rg_right > p:first-child{
#username,#password,#email,#name,#tel,#birthday,#checkcode{
border: 1px solid #A6A6A6 ;
background-color: #FFD026;
border: 1px solid #FFD026 ;
window.onload = function () {
document.getElementById("form").onsubmit = function () {
return checkUsername()&&checkPassword();
document.getElementById("username").onblur = checkUsername;
document.getElementById("username").onblur = checkPassword;
function checkUsername() {
let username = document.getElementById("username").value;
let reg_username = /^\w{6,12}$/;
let flag = reg_username.test(username);
let s_username = document.getElementById("s_username");
s_username.
innerHTML =
"
";
s_username.innerHTML = "用户名格式有误";
function checkPassword() {
let password = document.getElementById("password").value;
let reg_password = /^\w{6,12}$/;
let flag = reg_password.test(password);
let s_password = document.getElementById("s_password");
s_password.
innerHTML =
"
";
s_password.innerHTML = "密码格式有误";
<form action="#" id="form" method="get">
<td class="td_left"><label for="username">用户名label>td>
<input type="text" name="username" id="username" placeholder="请输入用户名">
<span id="s_username" class="error">span>
<td class="td_left"><label for="password">密码label>td>
<input type="password" name="password" id="password" placeholder="请输入密码">
<span id="s_password" class="error">span>
<td class="td_left"><label for="email">Emaillabel>td>
<td class="td_right"><input type="email" name="email" id="email" placeholder="请输入邮箱">td>
<td class="td_left"><label for="name">姓名label>td>
<td class="td_right"><input type="text" name="name" id="name" placeholder="请输入姓名">td>
<td class="td_left"><label for="tel">手机号label>td>
<td class="td_right"><input type="text" name="tel" id="tel" placeholder="请输入手机号">td>
<td class="td_left"><label>性别label>td>
<input type="radio" name="gender" value="male" checked> 男
<input type="radio" name="gender" value="female"> 女
<td class="td_left"><label for="birthday">出生日期label>td>
<td class="td_right"><input type="date" name="birthday" id="birthday" placeholder="请输入出生日期">td>
<td class="td_left"><label for="checkcode" >验证码label>td>
<td class="td_right"><input type="text" name="checkcode" id="checkcode" placeholder="请输入验证码">
<img id="img_check" src="img/verify_code.jpg">
<td colspan="2" id="td_sub"><input type="submit" id="btn_sub" value="注册">td>
<p>已有账号?<a href="#">立即登录a>p>

let reg_username = /^\w{6,12}$/;
当您在浏览器的控制台中输入代码示例时,它将定义一个名为reg_username的变量,并将其设置为一个正则表达式。
- {6,12}:指认由6到12个\w字符组成的重复次数
- $:匹配字符串的结尾 因此,该正则表达式用于匹配由6到12个字符、数字和下划线组成的字符串。
例如,reg_username.test("abcdefg1234567890)”将返回true,
而reg_username.test("12345")将返回false。
