ソースを参照

密码电话验证

Jonlin 6 年 前
コミット
83154f8c04

+ 14 - 1
application/user/controller/Register.php

@@ -15,6 +15,19 @@ class Register extends Controller
         Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/login.lang.php');
     }
 
+    /**
+     * 验证密码
+     * @return mixed
+     */
+    function checkPassword($password)
+    {
+        if (preg_match('/(?=^.{6,20}$)(?=.*\d)(?=.*[a-z])(?=.*[!@#$%^&*]).*$/', $password)) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
     /**
      * 注册
      * @return mixed
@@ -30,7 +43,7 @@ class Register extends Controller
             $captcha = input('post.captcha');
             $ch_box = input('post.ch_box');
 
-            //验证是否勾选协议
+            // 协议 校验
             if ($ch_box == false) {
                 //验证失败
                 $this->error('未勾选协议');

+ 56 - 4
application/user/view/register/index.html

@@ -71,14 +71,16 @@
                     <input type="text" name="user_email" placeholder="{:lang('email_address')}" required class="text">
                 </div>
                 <div class="form-group">
-                    <input type="text" name="user_password" placeholder="{:lang('install_pasword')}" required class="text">
-                    <div style="font-size: 10px;">密码必须包含有字母,数字,符号,密码长度为6-20个字符</div>
+                    <input type="text" name="user_password" id="user_password" placeholder="{:lang('install_pasword')}" required class="text">
+                    <div id="pwd" style="font-size: 10px;">密码必须包含有字母,数字,符号,密码长度为6-20个字符</div>
                 </div>
                 <div class="form-group">
-                    <input type="text" name="confirm_password" placeholder="{:lang('confirm_password')}" required class="text">
+                    <input type="text" id="confirm_password" name="confirm_password" placeholder="{:lang('confirm_password')}" required class="text">
+                    <div id="confirm_pwd"></div>
                 </div>
                 <div class="form-group">
-                    <input type="text" name="user_phone" placeholder="{:lang('phone')}" required class="text">
+                    <input type="text" id="user_phone" name="user_phone" placeholder="{:lang('phone')}" required class="text">
+                    <div id="phone"></div>
                 </div>
                 <div class="form-group">
                     <input type="text" name="captcha" placeholder="{:lang('login_captcha')}" required class="text" style="width:60%;float:left;">
@@ -94,6 +96,56 @@
     </div>
 </div>
 <script>
+    //密码 校验
+    $("#user_password").blur(function(){
+        var password = document.getElementById("user_password").value;
+        //console.log(password);
+        var patrn=/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
+        if (!patrn.exec(password)){
+            //console.log(1);
+            var addhtml = document.getElementById("pwd");
+            if(document.getElementById("tishi") == null){
+                addhtml.innerHTML = addhtml.innerText+'<span id="tishi" style="color:red;font-size: 12px;"><br>密码不合法</span>';
+            }
+        }else{
+            //console.log(2);
+            var remove = document.getElementById("tishi");
+            remove.parentNode.removeChild(remove);
+        }
+    });
+    $("#confirm_password").blur(function(){
+        var password = document.getElementById("confirm_password").value;
+        //console.log(password);
+        var patrn=/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
+        if (!patrn.exec(password)){
+            //console.log(1);
+            var addhtml = document.getElementById("confirm_pwd");
+            if(document.getElementById("tishi_pwd") == null){
+                addhtml.innerHTML = addhtml.innerText+'<span id="tishi_pwd" style="color:red;font-size: 12px;"><br>密码不合法</span>';
+            }
+        }else{
+            //console.log(2);
+            var remove = document.getElementById("tishi_pwd");
+            remove.parentNode.removeChild(remove);
+        }
+    });
+    //电话校验
+    $("#user_phone").blur(function(){
+        var password = document.getElementById("user_phone").value;
+        //console.log(password);
+        var patrn=/^1[3456789]\d{9}$/;
+        if (!patrn.exec(password)){
+            //console.log(1);
+            var addhtml = document.getElementById("phone");
+            if(document.getElementById("tishi_phone") == null){
+                addhtml.innerHTML = addhtml.innerText+'<span id="tishi_phone" style="color:red;font-size: 12px;"><br>电话号码不合法</span>';
+            }
+        }else{
+            //console.log(2);
+            var remove = document.getElementById("tishi_phone");
+            remove.parentNode.removeChild(remove);
+        }
+    });
     // 协议 校验
     function c_box(){
         var c_b = document.getElementById("ch_box");