Advertisement
Guest User

Untitled

a guest
May 14th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. //validation.functions.inc.php
  2.  
  3. <?php
  4.  
  5. #### Validation functions ####
  6.  
  7. function valid_email($email)
  8. {
  9.  
  10. // First, we check that there's one @ symbol, and that the lengths are right
  11. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
  12. {
  13. // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
  14. return false;
  15. }
  16. // Split it into sections to make life easier
  17. $email_array = explode("@", $email);
  18. $local_array = explode(".", $email_array[0]);
  19. for ($i = 0; $i < sizeof($local_array); $i++)
  20. {
  21. if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
  22. $local_array[$i]))
  23. {
  24. return false;
  25. }
  26. }
  27. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
  28. { // Check if domain is IP. If not, it should be valid domain name
  29. $domain_array = explode(".", $email_array[1]);
  30. if (sizeof($domain_array) < 2)
  31. {
  32. return false; // Not enough parts to domain
  33. }
  34. for ($i = 0; $i < sizeof($domain_array); $i++)
  35. {
  36. if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i]))
  37. {
  38. return false;
  39. }
  40. }
  41. }
  42. return true;
  43. }
  44.  
  45. function valid_username($username, $minlength = 3, $maxlength = 30)
  46. {
  47.  
  48. $username = trim($username);
  49.  
  50. if (empty($username))
  51. {
  52. return false; // it was empty
  53. }
  54. if (strlen($username) > $maxlength)
  55. {
  56. return false; // to long
  57. }
  58. if (strlen($username) < $minlength)
  59. {
  60.  
  61. return false; //toshort
  62. }
  63.  
  64. $result = ereg("^[A-Za-z0-9_\-]+$", $username); //only A-Z, a-z and 0-9 are allowed
  65.  
  66. if ($result)
  67. {
  68. return true; // ok no invalid chars
  69. } else
  70. {
  71. return false; //invalid chars found
  72. }
  73.  
  74. return false;
  75.  
  76. }
  77.  
  78. function valid_password($pass, $minlength = 6, $maxlength = 15)
  79. {
  80. $pass = trim($pass);
  81.  
  82. if (empty($pass))
  83. {
  84. return false;
  85. }
  86.  
  87. if (strlen($pass) < $minlength)
  88. {
  89. return false;
  90. }
  91.  
  92. if (strlen($pass) > $maxlength)
  93. {
  94. return false;
  95. }
  96.  
  97. $result = ereg("^[A-Za-z0-9_\-]+$", $pass);
  98.  
  99. if ($result)
  100. {
  101. return true;
  102. } else
  103. {
  104. return false;
  105. }
  106.  
  107. return false;
  108.  
  109. }
  110.  
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement