portal html css js resource

register.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. $(document).ready(function(){
  2. var userName=false;
  3. var phoneNumber=false;
  4. var phoneMa=false;
  5. var regNumber=false;
  6. var state;
  7. /*点击切换手机注册或者邮箱注册*/
  8. $(".loginWaySort").on("click","li",function(){
  9. $(this).addClass("liactive").siblings().removeClass("liactive");
  10. $(".loginWays ul").eq($(this).index()).removeClass("displayNone").siblings().addClass("displayNone");
  11. $(".cmpAllFrm").find("input").val("").find("button").attr("disabled","disabled");
  12. $(".frmmsg").find("span").text("");
  13. })
  14. /*校验名字*/
  15. //失去焦点后校验:1、输入框为空,提示:请输入您的真实姓名
  16. $("#yourName").blur(function(){
  17. if($("#yourName").val().length==0){
  18. $(".msgLog0").find("span").text("请输入您的真实姓名");
  19. userName=false;
  20. $(this).addClass("frmmsg-warning");
  21. }else{
  22. var inputval = $("#yourName").val().replace(/[^\u0000-\u00ff]/g, "aa").length;
  23. if(inputval > 20) {
  24. $(".msgLog0").find("span").text("姓名最长为10个汉字或20个英文字符");
  25. userName=false;
  26. $(this).addClass("frmmsg-warning");
  27. }else{
  28. $(".msgLog0").find("span").text("");
  29. $(this).removeClass("frmmsg-warning");
  30. userName=true;
  31. }
  32. }
  33. })
  34. $("#yourName").focus(function(){
  35. $(".msgLog0").find("span").text("");
  36. $(this).removeClass("frmmsg-warning");
  37. })
  38. /*校验手机号*/
  39. $("#lp_phone").blur(function(){
  40. phoneYesOrNo($(this));
  41. });
  42. $("#lp_phone").focus(function(){
  43. $(".msgLog1").find("span").text("");
  44. $(this).removeClass("frmmsg-warning");
  45. })
  46. /*校验手机是否已经注册函数*/
  47. function phoneYesOrNo($this) {
  48. var phone = $("#lp_phone").val();
  49. if(phone.length==0) {
  50. $("#getcode").attr("disabled","disabled");
  51. $(".msgLog1").find("span").text("请输入您的手机号码");
  52. phoneNumber=false;
  53. $this.addClass("frmmsg-warning");
  54. return;
  55. }else{
  56. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  57. if(!hunPhone.test(phone.trim())) {
  58. $("#getcode").attr("disabled","disabled");
  59. $(".msgLog1").find("span").text("请输入正确的手机号码");
  60. phoneNumber=false;
  61. $this.addClass("frmmsg-warning");
  62. return;
  63. }else{
  64. $(".msgLog1").find("span").text("");
  65. phoneNumber=true;
  66. }
  67. }
  68. $.ajax("/ajax/isReg?key=" + phone, {
  69. type: "GET",
  70. async: true,
  71. success: function($data) {
  72. if($data.success) {
  73. if($data.data == false) {
  74. $(".msgLog1").find("span").text("您的手机已被注册");
  75. $("#getcode").attr("disabled","disabled");
  76. phoneNumber=false;
  77. $this.addClass("frmmsg-warning");
  78. } else {
  79. $(".msgLog1").find("span").text("");
  80. $("#getcode").removeAttr("disabled");
  81. phoneNumber=true;
  82. $this.removeClass("frmmsg-warning");
  83. }
  84. }
  85. },
  86. error: function() {
  87. $.MsgBox.Alert('消息', '服务器请求失败')
  88. },
  89. });
  90. }
  91. /*校验手机验证码*/
  92. $(".companysc").focus(function(){
  93. $(".msgCmp03").find("span").text("");
  94. $(this).removeClass("frmmsg-warning");
  95. })
  96. $(".companysc").blur(function() {
  97. var authCode = $(".companysc").val();
  98. if(authCode.length == 0) {
  99. $(".msgCmp03").find("span").text("请输入您收到的短信验证码");
  100. phoneMa=false;
  101. $(this).addClass("frmmsg-warning");
  102. } else {
  103. var d = /^\d{4}$/;
  104. if(d.test(authCode.trim())) {
  105. $(".msgCmp03").find("span").text("");
  106. phoneMa=true;
  107. $(this).removeClass("frmmsg-warning");
  108. } else {
  109. $(".msgCmp03").find("span").text("验证码为4位数字");
  110. phoneMa=false;
  111. $(this).addClass("frmmsg-warning");
  112. }
  113. }
  114. })
  115. /*获取验证码*/
  116. $("#getcode").on("click",function(){
  117. doClick();
  118. getPhoneCode();
  119. });
  120. function doClick() {
  121. $("#getcode").html("60s后重新获取");
  122. $("#getcode").attr("disabled","disabled");
  123. var clickTime = new Date().getTime();
  124. var Timer = setInterval(function() {
  125. var nowTime = new Date().getTime();
  126. var second = Math.ceil(60 - (nowTime - clickTime) / 1000);
  127. if(second > 0) {
  128. $("#getcode").html(second + "s后重新获取");
  129. } else {
  130. clearInterval(Timer);
  131. $("#getcode").html("免费获取验证码");
  132. $("#getcode").removeAttr("disabled");
  133. }
  134. }, 1000);
  135. }
  136. /*发送手机验证码*/
  137. function getPhoneCode() {
  138. $.ajax("/ajax/regmobilephone", {
  139. type: "get",
  140. async: true,
  141. success: function(data) {
  142. if(data.success) {
  143. state = data.data;
  144. }
  145. },
  146. error: function() {
  147. $.MsgBox.Alert('message', '服务器连接超时')
  148. },
  149. data: {
  150. "mobilePhone": $("#lp_phone").val()
  151. },
  152. dataType: 'json'
  153. });
  154. }
  155. /*登录密码校验*/
  156. $("#phone_password").focus(function(){
  157. $(this).removeClass("frmmsg-warning");
  158. $(".msgLog3").find("span").text("");
  159. })
  160. $("#phone_password").blur(function(){
  161. setPassword();
  162. })
  163. function setPassword() {
  164. var password = $("#phone_password").val();
  165. if(password.length == 0) {
  166. $(".msgLog3").find("span").text("请设置您的登录密码");
  167. $("#phone_password").addClass("frmmsg-warning");
  168. regNumber=false;
  169. } else {
  170. var hunPhone = /^[0-9a-zA-Z]{6,}$/;
  171. if(hunPhone.test(password.trim())) {
  172. $(".msgLog3").find("span").text("");
  173. regNumber=true;
  174. $("#phone_password").removeClass("frmmsg-warning");
  175. } else {
  176. $(".msgLog3").find("span").text("密码由6-24个字符组成,区分大小写");
  177. regNumber=false;
  178. $("#phone_password").addClass("frmmsg-warning");
  179. }
  180. }
  181. }
  182. /*注册*/
  183. $("#regMess").on("keyup","#yourName,#lp_phone,.companysc,#phone_password",function(){
  184. if($("#yourName").val().length != 0 && $("#lp_phone").val().length != 0&&$(".companysc").val().length != 0&&$("#phone_password").val().length != 0) {
  185. $("#reg").removeAttr("disabled");
  186. }else{
  187. $("#reg").attr("disabled","disabled");
  188. }
  189. })
  190. /*注册函数*/
  191. function userReg() {
  192. console.log(state)
  193. $.ajax("/ajax/mobileReg", {
  194. type: "POST",
  195. async: true,
  196. success: function(data) {
  197. console.log(data);
  198. if(data.success) {
  199. loginagain();
  200. }else{
  201. if(data.code==-1){
  202. $.MsgBox.Alert('消息', '验证码已过期,请重新获取');
  203. }else if(data.code==-2){
  204. $(".msgCmp03 span").text('验证码错误,请检查后重试');
  205. }else if(data.code==-3){
  206. $(".msgCmp03 span").text('验证码错误,请检查后重试')
  207. }else if(data.code==0){
  208. $(".msgCmp03 span").text('验证码错误,请检查后重试')
  209. }
  210. }
  211. },
  212. error: function() {
  213. $.MsgBox.Alert('消息', '服务器请求失败');
  214. },
  215. data: {
  216. "state": state,
  217. "mobilePhone": $("#lp_phone").val(),
  218. "validateCode": $(".companysc").val(),
  219. "password": $("#phone_password").val(),
  220. "name" :$("#yourName").val()
  221. },
  222. dataType: 'json'
  223. });
  224. }
  225. function loginagain() {
  226. $.ajax("/ajax/login", {
  227. type: "POST",
  228. async: false,
  229. success: function(data) {
  230. console.log(data);
  231. if (data.success) {
  232. location.href = "fillinfo-select.html";
  233. }
  234. },
  235. error: function() {
  236. $.MsgBox.Alert('消息', '服务器请求失败');
  237. },
  238. data: {
  239. "pw": $("#phone_password").val(),
  240. "lk": $("#lp_phone").val()
  241. },
  242. dataType: 'json'
  243. });
  244. }
  245. /*手机注册*/
  246. $("#reg").click(function(){
  247. if(userName==true && phoneNumber==true && phoneMa==true && regNumber==true) {
  248. userReg();
  249. }
  250. })
  251. /*邮箱注册*/
  252. var oMailName=false;
  253. var oRegNumber=false;
  254. var emailPass=false;
  255. $("#mailName").focus(function(){
  256. $(".msgLog0").find("span").text("");
  257. $(this).removeClass("frmmsg-warning");
  258. })
  259. $("#mailName").blur(function(){
  260. if($("#mailName").val().length==0){
  261. $(".msgLog0").find("span").text("请输入您的真实姓名");
  262. $(this).addClass("frmmsg-warning");
  263. oMailName=false;
  264. }else{
  265. var inputval = $("#mailName").val().replace(/[^\u0000-\u00ff]/g, "aa").length;
  266. if(inputval > 20) {
  267. $(".msgLog0").find("span").text("姓名最长为10个汉字或20个英文字符");
  268. oMailName=false;
  269. $(this).addClass("frmmsg-warning");
  270. }else{
  271. $(".msgLog0").find("span").text("");
  272. oMailName=true;
  273. $(this).removeClass("frmmsg-warning");
  274. }
  275. }
  276. })
  277. /*邮箱登录密码校验*/
  278. $("#mailLoginPassword").focus(function(){
  279. $(".msgLog3").find("span").text("");
  280. $(this).removeClass("frmmsg-warning");
  281. })
  282. $("#mailLoginPassword").blur(function(){
  283. mailSetPassword();
  284. })
  285. function mailSetPassword() {
  286. passw();
  287. }
  288. /*校验登录密码函数*/
  289. function passw() {
  290. var password = $("#mailLoginPassword").val();
  291. if(password.length == 0) {
  292. $(".msgLog3").find("span").text("请设置您的登录密码");
  293. $("#mailLoginPassword").addClass("frmmsg-warning");
  294. oRegNumber=false;
  295. } else {
  296. var hunPhone = /^[0-9a-zA-Z]{6,}$/;
  297. if(hunPhone.test(password.trim())) {
  298. $(".msgLog3").find("span").text("");
  299. $("#mailLoginPassword").removeClass("frmmsg-warning");
  300. oRegNumber=true;
  301. } else {
  302. $(".msgLog3").find("span").text("密码由6-24个字符组成,区分大小写");
  303. $("#mailLoginPassword").addClass("frmmsg-warning");
  304. oRegNumber=false;
  305. }
  306. }
  307. }
  308. /*校验邮箱地址*/
  309. $("#mailAddress").focus(function(){
  310. $(".msgLog1").find("span").text("");
  311. $(this).removeClass("frmmsg-warning");
  312. })
  313. $("#mailAddress").blur(function(){
  314. oEmail();
  315. })
  316. /*校验邮箱地址函数*/
  317. function oEmail(){
  318. var email = $("#mailAddress").val();
  319. var gunf = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  320. if(email.length==0) {
  321. $(".msgLog1").find("span").text("请输入您的邮箱地址");
  322. $("#mailAddress").addClass("frmmsg-warning");
  323. emailPass = false;
  324. }else{
  325. if(gunf.test(email.trim())) {
  326. valEmail();
  327. } else {
  328. /*alert("请输入正确是邮箱地址");*/
  329. $(".msgLog1").find("span").text("请输入正确的邮箱地址");
  330. emailPass = false;
  331. $("#mailAddress").addClass("frmmsg-warning");
  332. }
  333. }
  334. }
  335. function valEmail() {
  336. $.ajax("/ajax/isReg?key=" + $("#mailAddress").val(), {
  337. type: "GET",
  338. async: true,
  339. success: function($data) {
  340. console.log($data);
  341. if($data.data == false) {
  342. $(".msgLog1").find("span").text("该账号已存在,请直接登录");
  343. $("#mailAddress").addClass("frmmsg-warning");
  344. emailPass = false;
  345. } else {
  346. $(".msgLog1").find("span").text("");
  347. $("#mailAddress").removeClass("frmmsg-warning");
  348. emailPass = true;
  349. }
  350. },
  351. error: function() {
  352. $.MsgBox.Alert('消息', '服务器请求失败')
  353. },
  354. });
  355. }
  356. /*注册是否点击*/
  357. $("#mailMess").on("keyup","#mailName,#mailAddress,#mailLoginPassword",function(){
  358. if ($("#mailName").val().length != 0 && $("#mailAddress").val().length != 0 && $("#mailLoginPassword").val().length != 0) {
  359. $("#mailReg").removeAttr("disabled");
  360. } else{
  361. $("#mailReg").attr("disabled","disabled");
  362. }
  363. })
  364. $("#mailReg").on("click",function(){
  365. if(oMailName==true && oRegNumber==true && emailPass==true) {
  366. mailRegistration();
  367. }
  368. })
  369. //邮箱注册提交
  370. function mailRegistration() {
  371. var mailVal = $("#mailAddress").val();
  372. var maiName = $("#mailName").val();
  373. var passwordVal = $("#mailLoginPassword").val();
  374. $.ajax("/ajax/emailReg", {
  375. type: "POST",
  376. async: true,
  377. success: function(data) {
  378. if(data.success) {
  379. /*$.cookie('mailVal', mailVal);
  380. location.href = "bind-mail.html";*/
  381. $(".waysBlock").hide();
  382. $(".maliTo").show();
  383. $(".loginWaySort").off("click");
  384. $(".loginWaySort li").css("cursor","auto");
  385. $("#omaile").text(mailVal);
  386. } else {
  387. $.MsgBox.Alert('消息', '邮箱发送失败');
  388. }
  389. },
  390. error: function() {
  391. $.MsgBox.Alert('消息', '邮箱发送失败');
  392. },
  393. data: {
  394. "mail": mailVal,
  395. "password": passwordVal,
  396. "name" : maiName
  397. },
  398. dataType: 'json'
  399. });
  400. }
  401. /*登录邮箱*/
  402. $("#loginMail").click(function(){
  403. var url = $("#mailAddress").val().split('@')[1];
  404. for (var j in hash){
  405. if(hash[url]==undefined){
  406. window.open("http://mail." + url);
  407. }else{
  408. window.open(hash[url]);
  409. }
  410. }
  411. })
  412. })