* Sanitizer: dev.w3.org/html5/spec-preview Follows-up8e8b15afc6. Use stable reference to www.w3.org/TR/html5 instead (currently from October 2014) instead of an old preview branch from 2012. * parserTests: dev.w3.org/html5 Follows-up959aa336a1. Url is now a dead end. Replaced with link to a draft from around that time. The relevant section no longer exists in the curent spec as it got split off into a separate spec. Maybe this one: https://url.spec.whatwg.org/#percent-encoded-bytes * Parser, HTMLIntField: dev.w3.org/html5 Use stable reference to www.w3.org/TR/html5 instead. * HTMLFloatField.php: dev.w3.org/html5 Url is now a dead end. Draft from around that time: http://www.w3.org/TR/2011/WD-html5-20110525/common-microsyntaxes.html#real-numbers The section "Real numbers" no longer exists in the current spec, but the Infrastructure chapter has a section on floating point numbers that describes the same sequence now. Change-Id: I7dcd49b6cd39785fb1b294e4eeaf39bda52337b2
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* A field that will contain a numeric value
|
|
*/
|
|
class HTMLFloatField extends HTMLTextField {
|
|
function getSize() {
|
|
return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 20;
|
|
}
|
|
|
|
function validate( $value, $alldata ) {
|
|
$p = parent::validate( $value, $alldata );
|
|
|
|
if ( $p !== true ) {
|
|
return $p;
|
|
}
|
|
|
|
$value = trim( $value );
|
|
|
|
# http://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
|
|
# with the addition that a leading '+' sign is ok.
|
|
if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
|
|
return $this->msg( 'htmlform-float-invalid' )->parseAsBlock();
|
|
}
|
|
|
|
# The "int" part of these message names is rather confusing.
|
|
# They make equal sense for all numbers.
|
|
if ( isset( $this->mParams['min'] ) ) {
|
|
$min = $this->mParams['min'];
|
|
|
|
if ( $min > $value ) {
|
|
return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
|
|
}
|
|
}
|
|
|
|
if ( isset( $this->mParams['max'] ) ) {
|
|
$max = $this->mParams['max'];
|
|
|
|
if ( $max < $value ) {
|
|
return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|