Guest User

Untitled

a guest
Jul 2nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. <?php
  2. DEFINE ("DB_HOST","localhost");
  3. DEFINE ("DB_USER","root");
  4. DEFINE ("DB_PASS","");
  5. DEFINE ("DB_SITE","pcm");
  6.  
  7. //Validators//
  8. function validateUsername($txtID)
  9. {
  10. if ($txtID == null)
  11. {
  12. return 'Please enter <strong>Username</strong>.<br/>';
  13. }
  14. else if (!preg_match("/^[0-9a-zA-Z_]{5,}$/",$txtID))
  15. {
  16. return '<strong>Username</strong> is invalid please read the following instruction.<br/>';
  17. }
  18. else if (UsernameExist($txtID))
  19. {
  20. return '<strong>Username</strong> given already exist. Try another.<br/>';
  21. }
  22. }
  23.  
  24. function validatePassword($txtPassword)
  25. {
  26. if ($txtPassword == null)
  27. {
  28. return 'Please enter <strong>Password</strong>.<br/>';
  29. }
  30. else if (!preg_match("/^.*(?=.{5,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/",$txtPassword))
  31. {
  32. return '<strong>Password</strong> is invalid please read the following instruction.<br/>';
  33. }
  34.  
  35. }
  36.  
  37. function validateConfirmPassword($txtConfirmPassword)
  38. {
  39. if ($txtConfirmPassword == null)
  40. {
  41. return 'Please Confirm <strong>Password</strong>.<br/>';
  42. }
  43. else if ($txtConfirmPassword != $_REQUEST['txtPassword'])
  44. {
  45. return 'The confirm password is not match with the password.<br/>';
  46. }
  47.  
  48. }
  49.  
  50. function validateName($txtName)
  51. {
  52. if ($txtName == null)
  53. {
  54. return 'Please enter your <strong>Full Name</strong>.<br/>';
  55. }
  56. else if(strlen($txtName) > 30)
  57. {
  58. return 'Character Cannot More Than 30 word.<br/>';
  59. }
  60. else if(!preg_match("/^[A-Z][a-zA-Z -]+$/",$txtName))
  61. {
  62. return '<strong>Name</strong> is invalid please read the following.<br/>';
  63. }
  64.  
  65. }
  66.  
  67. function validateAddress($txtAddress)
  68. {
  69. if ($txtAddress == null)
  70. {
  71. return 'Please enter your <strong>Address</strong>.<br/>';
  72. }
  73.  
  74. }
  75.  
  76. function validateDOB($txtDOB)
  77. {
  78. if ($txtDOB == null)
  79. {
  80. return 'Please enter your <strong>Date of Birth</strong>.<br/>';
  81. }
  82.  
  83. else if(!preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/",$txtDOB))
  84. {
  85. return '<strong>Date of Birth</strong> is invalid please read the following.<br/>';
  86. }
  87.  
  88. }
  89.  
  90.  
  91.  
  92. function validateGender($gender)
  93. {
  94. if ($gender == null)
  95. {
  96. return 'Please enter your <strong>Gender</strong>.<br/>';
  97. }
  98.  
  99. }
  100.  
  101. function validateEmail($txtEmail)
  102. {
  103. if ($txtEmail == null)
  104. {
  105. return 'Please enter your <strong>Email</strong>.<br/>';
  106. }
  107.  
  108. else if(!preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/",$txtEmail))
  109. {
  110. return '<strong>Email</strong> is invalid please read the following.<br/>';
  111. }
  112. else if (EmailExist($txtEmail))
  113. {
  114. return '<strong>Email</strong> given already exist. Try another.<br/>';
  115. }
  116.  
  117. }
  118.  
  119.  
  120. function UsernameExist($txtID)
  121. {
  122. $exist = false;
  123.  
  124. $con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SITE);
  125. $id = $con->real_escape_string($txtID);
  126. $sql = "SELECT * FROM member WHERE UserName = '$txtID'";
  127.  
  128. if ($result = $con->query($sql))
  129. {
  130. if ($result->num_rows > 0)
  131. {
  132. $exist = true;
  133. }
  134. }
  135.  
  136. $result->free();
  137. $con->close();
  138.  
  139. return $exist;
  140. }
  141.  
  142. function EmailExist($txtEmail)
  143. {
  144. $exist = false;
  145.  
  146. $con = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_SITE);
  147. $id = $con->real_escape_string($txtID);
  148. $sql = "SELECT * FROM member WHERE Email = '$txtEmail'";
  149.  
  150. if ($result = $con->query($sql))
  151. {
  152. if ($result->num_rows > 0)
  153. {
  154. $exist = true;
  155. }
  156. }
  157.  
  158. $result->free();
  159. $con->close();
  160.  
  161. return $exist;
  162. }
  163.  
  164.  
  165. ?>
Add Comment
Please, Sign In to add comment