Fix validate class lang load and test for numeric values
This commit is contained in:
parent
91b2d59458
commit
8ace96f495
@ -7595,7 +7595,7 @@ abstract class CommonObject
|
||||
} else { return true; }
|
||||
} elseif (in_array($type, array('double', 'real', 'price'))) {
|
||||
// is numeric
|
||||
if (!$validate->isDuration($fieldValue)) {
|
||||
if (!$validate->isNumeric($fieldValue)) {
|
||||
$this->setFieldError($fieldKey, $validate->error);
|
||||
return false;
|
||||
} else { return true; }
|
||||
|
||||
@ -55,18 +55,17 @@ class Validate
|
||||
{
|
||||
global $langs;
|
||||
|
||||
if ($outputLang) {
|
||||
if (empty($outputLang)) {
|
||||
$this->outputLang = $langs;
|
||||
} else {
|
||||
$this->outputLang = $outputLang;
|
||||
}
|
||||
|
||||
if (!is_object($this->outputLang) || !method_exists($outputLang, 'load')) {
|
||||
if (!is_object($this->outputLang) || !method_exists($this->outputLang, 'load')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Translate $outputLang */
|
||||
$outputLang->load('validate');
|
||||
$this->outputLang->loadLangs(array('validate', 'errors'));
|
||||
|
||||
$this->db = $db;
|
||||
}
|
||||
@ -229,6 +228,21 @@ class Validate
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Duration validity
|
||||
*
|
||||
* @param mixed $string to validate
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
public function isNumeric($string)
|
||||
{
|
||||
if (!is_numeric($string)) {
|
||||
$this->error = $this->outputLang->trans('RequireValidNumeric');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for boolean validity
|
||||
*
|
||||
|
||||
@ -315,6 +315,7 @@ RequireAtLeastXString = Requires at least %s character(s)
|
||||
RequireXStringMax = Requires %s character(s) max
|
||||
RequireAtLeastXDigits = Requires at least %s digit(s)
|
||||
RequireXDigitsMax = Requires %s digit(s) max
|
||||
RequireValidNumeric = Requires a numeric value
|
||||
RequireValidEmail = Email address is not valid
|
||||
RequireMaxLength = Length must be less than %s chars
|
||||
RequireMinLength = Length must be more than %s char(s)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user