Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / HTMLFloatField.php
blob2ef497895fad2265afc4737d67a4c21757c3f968
1 <?php
3 /**
4 * A field that will contain a numeric value
5 */
6 class HTMLFloatField extends HTMLTextField {
7 function getSize() {
8 return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 20;
11 function validate( $value, $alldata ) {
12 $p = parent::validate( $value, $alldata );
14 if ( $p !== true ) {
15 return $p;
18 $value = trim( $value );
20 # http://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
21 # with the addition that a leading '+' sign is ok.
22 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
23 return $this->msg( 'htmlform-float-invalid' )->parseAsBlock();
26 # The "int" part of these message names is rather confusing.
27 # They make equal sense for all numbers.
28 if ( isset( $this->mParams['min'] ) ) {
29 $min = $this->mParams['min'];
31 if ( $min > $value ) {
32 return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
36 if ( isset( $this->mParams['max'] ) ) {
37 $max = $this->mParams['max'];
39 if ( $max < $value ) {
40 return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
44 return true;