mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-28 13:36:12 +02:00
35 lines
714 B
PHP
35 lines
714 B
PHP
<?php
|
|
/**
|
|
* Text input field with validation for numeric values.
|
|
*
|
|
* @package forms
|
|
* @subpackage fields-formattedinput
|
|
*/
|
|
class NumericField extends TextField{
|
|
|
|
public function Type() {
|
|
return 'numeric text';
|
|
}
|
|
|
|
/** PHP Validation **/
|
|
public function validate($validator){
|
|
if($this->value && !is_numeric(trim($this->value))){
|
|
$validator->validationError(
|
|
$this->name,
|
|
_t(
|
|
'NumericField.VALIDATION', "'{value}' is not a number, only numbers can be accepted for this field",
|
|
array('value' => $this->value)
|
|
),
|
|
"validation"
|
|
);
|
|
return false;
|
|
} else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public function dataValue() {
|
|
return (is_numeric($this->value)) ? $this->value : 0;
|
|
}
|
|
}
|