From 3a89da18438cff6ab4b10dc6da96d1e061da4e4f Mon Sep 17 00:00:00 2001 From: majestick Date: Sun, 21 Jul 2013 11:24:22 +0200 Subject: [PATCH] added 2 new functions added is_ip and is_fqdn for alt_name check --- include/my_functions.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/my_functions.php b/include/my_functions.php index ee3f998..a381d1b 100644 --- a/include/my_functions.php +++ b/include/my_functions.php @@ -185,6 +185,30 @@ function is_email($v) { return (eregi('^[^@ ]+\@[^@ ]+\.[A-Z]{2,4}$',$v) ? true : false); } +# +# Returns True if the given string is a IP address +# +function is_ip( $ip = null ) { + if( !$ip or strlen(trim($ip)) == 0){ + return false; + } + $ip=trim($ip); + if(preg_match("/^[0-9]{1,3}(.[0-9]{1,3}){3}$/",$ip)) { + foreach(explode(".", $ip) as $block) + if($block<0 || $block>255 ) + return false; + return true; + } + return false; +} + +# +# Returns True if the given string is a valid FQDN +# +function is_fqdn($FQDN) { + return (!empty($FQDN) && preg_match('/(?=^.{1,254}$)(^(?:(?!\d|-)[a-z0-9\-]{1,63}(? 0); +} + # # Checks regexp in every element of an array, returns TRUE as soon # as a match is found.