You are here

function fapi_validation_rule_limit_decimals in Form API Validation 7.2

Limits decimals allowed

1 string reference to 'fapi_validation_rule_limit_decimals'
fapi_validation_fapi_validation_rules in ./fapi_validation.module
Implementation of hook_fapi_validation_rules

File

./fapi_validation.module, line 363

Code

function fapi_validation_rule_limit_decimals($value, $params) {
  if (!is_numeric($value)) {
    return FALSE;
  }
  if (count($params) > 0) {
    $value = (double) $value;
    $pattern = '/^[^\\.]*\\.?[0-9]{0,' . $params[0] . '}$/';
    return (bool) preg_match($pattern, (string) $value);
  }
  return TRUE;
}