博客列表 >完成一个用户注册页面, 用xmind文件中总结的字符串函数库,对表单字段进行验证? 比如限制密码长度,两次密码须一致, 验证码验证,用户名首位需是字母等等?

完成一个用户注册页面, 用xmind文件中总结的字符串函数库,对表单字段进行验证? 比如限制密码长度,两次密码须一致, 验证码验证,用户名首位需是字母等等?

ッ小眼睛っ
ッ小眼睛っ原创
2021年08月10日 21:11:01452浏览
  1. <?php
  2. if(!empty($_POST['username']) && !empty($_POST['user_password']) && !empty($_POST['user_password_s']) && !empty($_POST['code'])){
  3. if((ord(ucfirst($_POST['username']){0}) < 65) || (ord(ucfirst($_POST['username']){0}) > 90 )){
  4. exit(json_encode([
  5. 'msg'=>'用户名不合法'
  6. ]));
  7. }
  8. if(strcmp($_POST['user_password'],$_POST['user_password_s'])){
  9. exit(json_encode([
  10. 'msg'=>'密码不一致'
  11. ]));
  12. }
  13. if(strcasecmp($code_s,$code)){
  14. exit(json_encode([
  15. 'msg'=>'验证码错误'
  16. ]));
  17. }
  18. exit(json_encode([
  19. 'msg'=>'注册成功'
  20. ]));
  21. }else{
  22. $code_s = substr(md5(mt_rand()),0,5);
  23. }
  24. ?>
  25. <!DOCTYPE html>
  26. <html lang="zh-CN">
  27. <head>
  28. <meta charset="utf-8">
  29. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  30. <meta name="viewport" content="width=device-width, initial-scale=1">
  31. <title>用户登陆</title>
  32. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  33. </head>
  34. <body>
  35. <div class="container theme-showcase" role="main">
  36. <br>
  37. <div class="jumbotron">
  38. <h2><b>用户登陆</b></h2>
  39. </div>
  40. <div class="input-group">
  41. <div class="input-group-prepend">
  42. <span class="input-group-text">账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</span>
  43. </div>
  44. <input type="text" class="form-control" id="username" placeholder="请输入注册账号" required="">
  45. </div>
  46. <br>
  47. <div class="input-group">
  48. <div class="input-group-prepend">
  49. <span class="input-group-text">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码</span>
  50. </div>
  51. <input type="password" class="form-control" id="user_password" placeholder="请输入注册密码" required="">
  52. </div>
  53. <br>
  54. <div class="input-group">
  55. <div class="input-group-prepend">
  56. <span class="input-group-text">确认密码</span>
  57. </div>
  58. <input type="password" class="form-control" id="user_password_s" placeholder="请再次输入注册密码" required="">
  59. </div>
  60. <br>
  61. <div class="row">
  62. <div class="col">
  63. <div class="input-group">
  64. <div class="input-group-prepend">
  65. <span class="input-group-text">验&nbsp;&nbsp;证&nbsp;&nbsp;码</span>
  66. </div>
  67. <input type="text" class="form-control" id="code" placeholder="请输入验证" required="" >
  68. </div>
  69. </div>
  70. <div class="col">
  71. <div class="input-group">
  72. <div class="input-group-prepend">
  73. <span class="input-group-text"><?=$code_s?></span>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. <br>
  79. <button type="button" class="btn btn-primary btn-lg btn-block" id="Pots_go">注册</button>
  80. </div>
  81. <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
  82. <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
  83. <script>
  84. $(function($) {
  85. $('#Pots_go').on('click', function () {
  86. $.ajax({
  87. url:'index.php',
  88. dataType:'json',
  89. type:'POST',
  90. data:{
  91. 'username':$('#username').val(),
  92. 'user_password':$('#user_password').val(),
  93. 'user_password_s':$('#user_password_s').val(),
  94. 'code':$('#code').val()
  95. },
  96. success: function (data, status) {
  97. alert(data.msg);
  98. },
  99. error: function (request, error, thrown) {
  100. }
  101. })
  102. })
  103. })
  104. </Script>
  105. </body>
  106. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议