You are here

function fapi_validation_rule_decimal in Form API Validation 6

Same name and namespace in other branches
  1. 7.2 fapi_validation.module \fapi_validation_rule_decimal()
  2. 7 fapi_validation.module \fapi_validation_rule_decimal()
1 string reference to 'fapi_validation_rule_decimal'
fapi_validation_fapi_validation_rules in ./fapi_validation.module
Implementation of hook_fapi_validation_rules

File

./fapi_validation.module, line 279

Code

function fapi_validation_rule_decimal($value, $params) {
  if (count($params) == 2) {
    $pattern = '/^[0-9]{' . $params[0] . '}\\.[0-9]{' . $params[1] . '}$/';
    return (bool) preg_match($pattern, (string) $value);
  }
  else {
    return (bool) preg_match('/\\d+\\.\\d+/', $value);
  }
  return FALSE;
}