Guest User

Untitled

a guest
Mar 6th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. $(document).ready(function() {
  2. $('#sub').click(function(e) {
  3.  
  4. var fname = $('#fname').val();
  5. var lname = $('#lname').val();
  6. var email = $('#email').val();
  7. var age = $('#age').val();
  8. var username = $('#Username').val();
  9. var Password = $('#Password').val();
  10. var CPassword = $('#CPassword').val();
  11. var username_flag = false;
  12.  
  13. var name_regex = /^[a-zA-Z]+$/;
  14. var email_regex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
  15. //var add_regex = /^[0-9a-zA-Z]+$/;
  16. $("#Username").blur(function() {
  17. $.ajax({
  18. url: "./display.php",
  19. data:'Username='+$("#Username").val(),
  20. type: "POST",
  21. success:function(data){
  22. console.log(data);
  23. if(data == "true"){
  24. $("#user-availability-status").html("not avilable");
  25. username_flag = true;
  26. }
  27. else{
  28. username_flag = false;
  29. $("#user-availability-status").html("avilable");
  30. }
  31. },
  32. });
  33. });
  34.  
  35. if (fname.length == 0) {
  36. $('#head').text("* All fields are mandatory *");
  37. $("#fname").focus();
  38. return false;
  39. }
  40.  
  41. else if (!fname.match(name_regex) || fname.length == 0) {
  42. $('#p1').text("For your first name please use alphabets only ");
  43. $("#fname").focus();
  44. return false;
  45. }
  46.  
  47. else if (!lname.match(name_regex) || lname.length == 0) {
  48. $('#p2').text(" For your last name please use alphabets only");
  49. $("#lname").focus();
  50. return false;
  51. }
  52.  
  53. else if (!email.match(email_regex) || email.length == 0) {
  54. $('#p3').text("Please enter a valid email address");
  55. $("#email").focus();
  56. return false;
  57. }
  58.  
  59. else if (isNaN(age)||age<1||age>100){
  60. $('#p4').text("Please enter a valid age");
  61. $("#age").focus();
  62. return false;
  63. }
  64.  
  65.  
  66. else if ((!(username.length >= 6 ) || username.length == 0) && username_flag == true ) {
  67. $('#p5').text(" Please enter above 6 characters and username avilable");
  68. $("#username").focus();
  69. return false;
  70. }
  71.  
  72. else if(!(Password.length >=6) || Password.length ==0){
  73. $('#p6').text("Please enter above 6 characters");
  74. $("#Password").focus();
  75. return false;
  76. }
  77.  
  78. else if(Password!=CPassword){
  79. $('#p7').text("password do not match");
  80. $("#Password").focus();
  81. return false;
  82. }
  83.  
  84. else {
  85.  
  86. $.ajax({
  87. type :"POST",
  88. url :"insert.php",
  89. data: datastring,
  90. cache: false,
  91. success: function(result){
  92. alert(result);
  93. }
  94. });
  95. // alert("Form Submitted Successfuly!");
  96. // return true;
  97. }
  98. });
  99. });
Add Comment
Please, Sign In to add comment