url, email and ip validation with php


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

Simple PHP functions to validate url, email address and ip, functions will 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_url($url){
  4. $p1 ='/(http|https|ftp):\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i';
  5. return preg_match($p1, $url);
  6. }
  7.  
  8.  
  9.  
  10. function is_valid_email($email){
  11. if (filter_var($email, FILTER_VALIDATE_EMAIL))
  12. return true;
  13. else
  14. return false;
  15. }
  16.  
  17.  
  18. function is_valid_ip($ip){
  19. if (filter_var($ip, FILTER_VALIDATE_IP))
  20. return true;
  21. else
  22. return false;
  23. }
  24.  
  25. ?>

URL: http://function-code.blogspot.com/2013/10/url-email-ip-validation-with-php.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.