registration.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function Login(){
  2. window.location.href='/login';
  3. };
  4. $(function (){
  5. var firstname = $("input[name='firstname']");
  6. var lastname = $("input[name='lastname']");
  7. var email = $("input[name='email']");
  8. var phone = $("input[name='phone']");
  9. var username = $("input[name='username']");
  10. var password = $("input[name='password']");
  11. var confirmpwd = $("input[name='confirmpwd']");
  12. var status = false;
  13. var form = $("form");
  14. firstname.blur(function(){ // rita blur 取消焦點時
  15. var span = $("#firstname-span");
  16. if(firstname.val() == ''){
  17. span.text("Field is requied");
  18. status = false;
  19. }else{
  20. span.text("");
  21. status = true;
  22. };
  23. });
  24. lastname.blur(function(){
  25. var span = $("#lastname-span");
  26. if(lastname.val() == ''){
  27. span.text("Field is requied");
  28. status = false;
  29. }else{
  30. span.text("");
  31. status = true;
  32. };
  33. });
  34. email.blur(function(){
  35. var span = $("#email-span");
  36. if(email.val().indexOf('@') == -1){
  37. span.text("Incorrect email address");
  38. status = false;
  39. }else{
  40. span.text("");
  41. status = true;
  42. $.get('/check_email','email='+email.val(),function(resText){
  43. if(resText.errMsg){
  44. $("#firstname_span").text("This email is already registered");
  45. status = false;
  46. }else{
  47. $("#firstname_span").text("");
  48. status = true;
  49. };
  50. },'json');
  51. };
  52. });
  53. phone.blur(function(){
  54. var span = $("#phone-span");
  55. if(phone.val().length < 8 || isNaN(phone.val()) == true){
  56. span.text("Wrong phone number");
  57. status = false;
  58. }else{
  59. span.text("");
  60. status = true;
  61. };
  62. });
  63. username.blur(function(){
  64. $.get("/check_username","username="+username.val(),function(resText){
  65. if(resText.errMsg){
  66. $("#firstname-span").text("This username is already registered");
  67. status = false;
  68. }else{
  69. $("#firstname-span").text("");
  70. status = true;
  71. };
  72. },'json');
  73. });
  74. confirmpwd.blur(function(){
  75. var span = $("#password-span");
  76. if(password.val() != confirmpwd.val()){
  77. span.text("Passwords does not match");
  78. status = false;
  79. }else{
  80. span.text("");
  81. status = true;
  82. };
  83. });
  84. form.submit(function(){
  85. if((status == true) && (password.val() != '') && (confirmpwd.val() != '')){
  86. return true;
  87. }else{
  88. alert("Please type your infomation");
  89. return false;
  90. };
  91. });
  92. });