helpers_form.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. function checkEmail($email) {
  3. // format: abc123@cde456.aa | abc123@cde456.aaa
  4. return !! preg_match(" /^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/ ", $email);
  5. }
  6. function checkPhone($phone) {
  7. // format: 00 00 00 00 00,
  8. return !! preg_match(" \^(\d\d\s){4}(\d\d)$\ ", $phone);
  9. }
  10. function checkUrl($url) {
  11. // format http://www.example.com | www.example.com | http://subdomain.example.com | example.com
  12. return !! preg_match(" \^(http|https|ftp):\/\/([\w]*)\.([\w]*)\.(com|net|org|biz|info|mobi|us|cc|bz|tv|ws|name|co|me)(\.[a-z]{1,3})?\z/i ", $url);
  13. }
  14. function checkLogin($login, $min_length=3, $max_length=16) {
  15. // format: abc_123
  16. return !! preg_match(" \^[a-zA-Z0-9_]{" . $min_length . "," . $max_length . "}$\ ", $login);
  17. }
  18. function checkDateFr($date) {
  19. // format: 00/00/0000
  20. return !! preg_match(" \^([0-3][0-9]})(/)([0-9]{2,2})(/)([0-3]{2,2})$\ ", $date);
  21. }
  22. function checkZipcode($zipcode) {
  23. // format: 00000
  24. return !! preg_match(" \^[0-9]{5,5}$\ ", $zipcode);
  25. }
  26. function checkIPv4($ip) {
  27. return !! preg_match(" \^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$\ ", $ip);
  28. }
  29. function checkHexColor($color) {
  30. return !! preg_match(" \^#(?:(?:[a-f\d]{3}){1,2})$/i ", $color);
  31. }