41 |
* This holds the last error message |
* This holds the last error message |
42 |
*/ |
*/ |
43 |
var $_error_message = ''; |
var $_error_message = ''; |
44 |
|
|
45 |
|
/** |
46 |
|
* This is the FormErrors object |
47 |
|
*/ |
48 |
|
var $_FormErrors = NULL; |
49 |
|
|
50 |
|
|
51 |
|
/** |
52 |
|
* The constructor used to set the |
53 |
|
* form errors object used by this class |
54 |
|
* to do error text lookups |
55 |
|
* |
56 |
|
* @param FormErrors object |
57 |
|
*/ |
58 |
|
function FormValidation(&$error_obj) { |
59 |
|
$this->_FormErrors = &$error_obj; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
|
90 |
function _error($code, $message=NULL) { |
function _error($code, $message=NULL) { |
91 |
$this->_error_code = $code; |
$this->_error_code = $code; |
92 |
if ($message == NULL) { |
if ($message == NULL) { |
93 |
$err = new FormErrors; |
$this->_error_message = $this->_FormErrors->get_error_msg($code); |
|
$this->_error_message = $err->get_error_msg($code); |
|
94 |
unset( $err ); |
unset( $err ); |
95 |
} else { |
} else { |
96 |
$this->_error_message = $message; |
$this->_error_message = $message; |
309 |
* @param string - the value to validate |
* @param string - the value to validate |
310 |
* @return TRUE = succes FALSE = failed |
* @return TRUE = succes FALSE = failed |
311 |
*/ |
*/ |
312 |
function is_domainname ($name) { |
function is_domainname ($name, $forbid_www=FALSE) { |
313 |
|
if (!ereg( "^(([a-z0-9]{1,63}|". |
314 |
// letters, digits and ".-" only |
"([a-z0-9][a-z0-9\-]{1,61}[a-z0-9]))\.)+". |
315 |
if ( !$this->is_alphanum($name, ".-") ) { |
"[a-z]{2,63}$", $name )) { |
316 |
return $this->_error("INVALID_HOST_NAME"); |
return $this->_error("INVALID_HOST_NAME"); |
317 |
} |
} else if ($forbid_www && ereg( "^www\.", $name )) { |
|
|
|
|
$len = strlen($name); |
|
|
if ( $len > VALIDATE_MAX_HOSTNAME_LENGTH ) { |
|
|
return $this->_error("INVALID_LENGTH"); |
|
|
} |
|
|
|
|
|
// Error if it doesn't start with an alphabet or digit |
|
|
if ( !eregi("^[a-z0-9]", $name) ) { |
|
|
return $this->_error("INVALID_HOST_NAME"); |
|
|
} |
|
|
|
|
|
// Error if it contains no alphabets |
|
|
if ( !eregi("[a-z]", $name) ) { |
|
|
return $this->_error("INVALID_HOST_NAME"); |
|
|
} |
|
|
|
|
|
// Cannot contain two or more consecutive dots. |
|
|
if ( ereg("\.\.+", $name) ) { |
|
318 |
return $this->_error("INVALID_HOST_NAME"); |
return $this->_error("INVALID_HOST_NAME"); |
319 |
} |
} |
320 |
return TRUE; |
return TRUE; |
1026 |
$month = $x[1]; |
$month = $x[1]; |
1027 |
$day = $x[2]; |
$day = $x[2]; |
1028 |
|
|
1029 |
$d = sx_date_today(); |
$d = explode(",",date("Y,m,d")); |
1030 |
$today = $d[0] * 10000 + $d[1]; |
$today = $d[0] * 10000 + $d[1]; |
1031 |
$exp = $year * 10000 + $month; |
$exp = $year * 10000 + $month; |
1032 |
if ( $exp < $today ) { |
if ( $exp < $today ) { |
1172 |
} |
} |
1173 |
return TRUE; |
return TRUE; |
1174 |
} |
} |
1175 |
|
|
1176 |
|
/** |
1177 |
|
* Validate if the string matches a regex |
1178 |
|
* |
1179 |
|
* @param string - the regex string |
1180 |
|
* @param string - the value to validate |
1181 |
|
* @return TRUE = succes FALSE = failed |
1182 |
|
*/ |
1183 |
|
function is_regex($regex, $str) { |
1184 |
|
if (preg_match($regex, $str)) { |
1185 |
|
return TRUE; |
1186 |
|
} else { |
1187 |
|
return FALSE; |
1188 |
|
} |
1189 |
|
} |
1190 |
|
|
1191 |
} |
} |
1192 |
?> |
?> |