Project

General

Profile

« Previous | Next » 

Revision ee956d19

Added by Renato Botelho over 8 years ago

Introduce is_intrange() to validate a range of integers delimited by ':' or '-'

View differences:

src/etc/inc/util.inc
1077 1077
	return is_validaliasname($name, true, $object);
1078 1078
}
1079 1079

  
1080
/*
1081
 * returns true if $range is a valid integer range between $min and $max
1082
 * range delimiter can be ':' or '-'
1083
 */
1084
function is_intrange($range, $min, $max) {
1085
	$values = preg_split("/[:-]/", $range);
1086

  
1087
	if (!is_array($values) || count($values) != 2) {
1088
		return false;
1089
	}
1090

  
1091
	if (!ctype_digit($values[0]) || !ctype_digit($values[1])) {
1092
		return false;
1093
	}
1094

  
1095
	$values[0] = intval($values[0]);
1096
	$values[1] = intval($values[1]);
1097

  
1098
	if ($values[0] >= $values[1]) {
1099
		return false;
1100
	}
1101

  
1102
	if ($values[0] < $min || $values[1] > $max) {
1103
		return false;
1104
	}
1105

  
1106
	return true;
1107
}
1108

  
1080 1109
/* returns true if $port is a valid TCP/UDP port */
1081 1110
function is_port($port) {
1082 1111
	if (ctype_digit($port) && ((intval($port) >= 1) && (intval($port) <= 65535))) {

Also available in: Unified diff