Posted By

codingforever99 on 10/25/13


Tagged

php date password validation Userame


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

stupoare


username, password and date validation with php


 / Published in: PHP
 

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

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.

  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. ?>

Report this snippet  

You need to login to post a comment.