user.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. @Name:layuiAdmin 用户登入和注册等
  3. @Author:贤心
  4. @Site:http://www.layui.com/admin/
  5. @License: LPPL
  6. */
  7. layui.define('form', function(exports){
  8. var $ = layui.$
  9. ,layer = layui.layer
  10. ,laytpl = layui.laytpl
  11. ,setter = layui.setter
  12. ,view = layui.view
  13. ,admin = layui.admin
  14. ,form = layui.form;
  15. var $body = $('body');
  16. //自定义验证
  17. form.verify({
  18. nickname: function(value, item){ //value:表单的值、item:表单的DOM对象
  19. if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
  20. return '用户名不能有特殊字符';
  21. }
  22. if(/(^\_)|(\__)|(\_+$)/.test(value)){
  23. return '用户名首尾不能出现下划线\'_\'';
  24. }
  25. if(/^\d+\d+\d$/.test(value)){
  26. return '用户名不能全为数字';
  27. }
  28. }
  29. //我们既支持上述函数式的方式,也支持下述数组的形式
  30. //数组的两个值分别代表:[正则匹配、匹配不符时的提示文字]
  31. ,pass: [
  32. /^[\S]{6,12}$/
  33. ,'密码必须6到12位,且不能出现空格'
  34. ]
  35. });
  36. //发送短信验证码
  37. admin.sendAuthCode({
  38. elem: '#LAY-user-getsmscode'
  39. ,elemPhone: '#LAY-user-login-cellphone'
  40. ,elemVercode: '#LAY-user-login-vercode'
  41. ,ajax: {
  42. url: layui.setter.base + 'json/user/sms.js' //实际使用请改成服务端真实接口
  43. }
  44. });
  45. //更换图形验证码
  46. $body.on('click', '#LAY-user-get-vercode', function(){
  47. var othis = $(this);
  48. this.src = 'https://www.oschina.net/action/user/captcha?t='+ new Date().getTime()
  49. });
  50. //对外暴露的接口
  51. exports('user', {});
  52. });