mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
3e307e00fe
removed in 9f3344b355
35 lines
702 B
PHP
35 lines
702 B
PHP
<?php
|
|
/**
|
|
* A Single Numeric field extending a typical
|
|
* TextField but with validation.
|
|
* @package forms
|
|
* @subpackage fields-formattedinput
|
|
*/
|
|
class NumericField extends TextField{
|
|
|
|
function Type() {
|
|
return 'numeric text';
|
|
}
|
|
|
|
/** PHP Validation **/
|
|
function validate($validator){
|
|
if($this->value && !is_numeric(trim($this->value))){
|
|
$validator->validationError(
|
|
$this->name,
|
|
sprintf(
|
|
_t('NumericField.VALIDATION', "'%s' is not a number, only numbers can be accepted for this field"),
|
|
$this->value
|
|
),
|
|
"validation"
|
|
);
|
|
return false;
|
|
} else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function dataValue() {
|
|
return (is_numeric($this->value)) ? $this->value : 0;
|
|
}
|
|
}
|