MediaWiki
master
Toggle main menu visibility
HTMLIntField.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\HTMLForm\Field;
4
10
class
HTMLIntField
extends
HTMLFloatField
{
11
16
public
function
validate
( $value, $alldata ) {
17
$p = parent::validate( $value, $alldata );
18
19
if
( $p !==
true
) {
20
return
$p;
21
}
22
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'
);
31
}
32
33
return
true
;
34
}
35
}
36
38
class_alias( HTMLIntField::class,
'HTMLIntField'
);
MediaWiki\HTMLForm\Field\HTMLFloatField
A field that will contain a numeric value.
Definition
HTMLFloatField.php:10
MediaWiki\HTMLForm\Field\HTMLIntField
A field that must contain a number.
Definition
HTMLIntField.php:10
MediaWiki\HTMLForm\Field\HTMLIntField\validate
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
Definition
HTMLIntField.php:16
MediaWiki\HTMLForm\HTMLFormField\msg
msg( $key,... $params)
Get a translated interface message.
Definition
HTMLFormField.php:138
includes
HTMLForm
Field
HTMLIntField.php
Generated on
for MediaWiki by
1.18.0