MediaWiki REL1_35
HTMLIntField.php
Go to the documentation of this file.
1<?php
2
9
14 public function validate( $value, $alldata ) {
15 $p = parent::validate( $value, $alldata );
16
17 if ( $p !== true ) {
18 return $p;
19 }
20
21 # https://www.w3.org/TR/html5/infrastructure.html#signed-integers
22 # with the addition that a leading '+' sign is ok. Note that leading zeros
23 # are fine, and will be left in the input, which is useful for things like
24 # phone numbers when you know that they are integers (the HTML5 type=tel
25 # input does not require its value to be numeric). If you want a tidier
26 # value to, eg, save in the DB, clean it up with intval().
27 if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ?? '' ) ) ) {
28 return $this->msg( 'htmlform-int-invalid' );
29 }
30
31 return true;
32 }
33}
A field that will contain a numeric value.
msg( $key,... $params)
Get a translated interface message.
A field that must contain a number.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...