Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLIntField.php
blob818db6886c36f72ed1c8477ed7dca261ba0c3de8
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 /**
6 * A field that must contain a number
8 * @stable to extend
9 */
10 class HTMLIntField extends HTMLFloatField {
12 /**
13 * @inheritDoc
14 * @stable to override
16 public function validate( $value, $alldata ) {
17 $p = parent::validate( $value, $alldata );
19 if ( $p !== true ) {
20 return $p;
23 # https://www.w3.org/TR/html5/infrastructure.html#signed-integers
24 # with the addition that a leading '+' sign is ok. Note that leading zeros
25 # are fine, and will be left in the input, which is useful for things like
26 # phone numbers when you know that they are integers (the HTML5 type=tel
27 # input does not require its value to be numeric). If you want a tidier
28 # value to, eg, save in the DB, clean it up with intval().
29 if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ?? '' ) ) ) {
30 return $this->msg( 'htmlform-int-invalid' );
33 return true;
37 /** @deprecated class alias since 1.42 */
38 class_alias( HTMLIntField::class, 'HTMLIntField' );