username, password and date validation with php


/ Published in: PHP
Save to your folder(s)

Simple PHP functions to validate username, password and date, functions check the input format and allowed characters and then return TRUE for valid data and FALSE for invalid data.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function is_valid_username($username){
  4. // accepted username length between 5 and 20
  5. if (preg_match('/^\w{5,20}$/', $username))
  6. return true;
  7. else
  8. return false;
  9. }
  10.  
  11.  
  12. function is_valid_password($pwd){
  13. // accepted password length between 5 and 20, start with character.
  14. if (preg_match("/^[a-zA-Z][0-9a-zA-Z_!$@#^&]{5,20}$/", $pwd))
  15. return true;
  16. else
  17. return false;
  18. }
  19.  
  20.  
  21. function is_valid_date($date){
  22. //============ date format dd-mm-yyyy
  23. if(preg_match("/^(\d{2})-(\d{2})-(\d{4})$/", $date, $sdate))
  24. if(checkdate($sdate[2], $sdate[1], $sdate[3]))
  25. return true;
  26. }
  27.  
  28. ?>

URL: http://function-code.blogspot.com/2013/10/username-password-and-date-validation.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.