layui模板注册表单

今天晚上用layui模板做了一个简单的注册表单,功能主要有可以js验证密码重复,可以验证手机号码。

这是界面

layui模板注册表单_第1张图片

 

 下面是我的html文件代码

DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
head>
<body>

<form class="layui-form" action="register?method1=register" method="post">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>用户注册legend>
    fieldset>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名label>
        <div class="layui-input-inline">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        div>
    div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码label>
        <div class="layui-input-inline">
            <input type="password" id="pwd1"  name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        div>
        <div class="layui-form-mid layui-word-aux">辅助文字div>
    div>
    <div class="layui-form-item">
        <label class="layui-form-label">重复密码label>
        <div class="layui-input-inline">
            <input type="password" id="pwd2" onkeyup="validate()" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        div>
    div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号label>
        <div class="layui-input-inline">
            <input type="text" name="phone" id="phone" onblur="isPhone(this.value)" required lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
        div>
    div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位label>
        <div class="layui-input-inline">
            <select name="work" lay-verify="required">
                <option value="">option>
                <option value="政府机构">政府机构option>
                <option value="个体户">个体户option>
            select>
        div>
    div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn" type="submit" value="立即提交">input>
            <button type="reset" class="layui-btn layui-btn-primary">重置button>
        div>
    div>
form>
<script src="layui/layui.all.js" charset="utf-8">script>
<script>
    //Demo
    function validate() {
        var pwd1 = document.getElementById("pwd1").value;
        var pwd2 = document.getElementById("pwd2").value;
        
        if(pwd1!=pwd2) {
            alert("两次密码输入不同");
            document.getElementById('pwd2').value="";
        }
    }
    function isPhone(card)
    {
        // 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
        var reg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
        if(reg.test(card) === false)
        {
            alert("电话号码输入有误!");
            document.getElementById('phone').value="";
        }
    }
    layui.use('form', function(){
        var form = layui.form;
    });

script>
body>
html>

 

你可能感兴趣的:(layui模板注册表单)