Split includes/HTMLForm
[lhc/web/wiklou.git] / includes / htmlform / HTMLIntField.php
1 <?php
2 /**
3 * A field that must contain a number
4 */
5 class HTMLIntField extends HTMLFloatField {
6 function validate( $value, $alldata ) {
7 $p = parent::validate( $value, $alldata );
8
9 if ( $p !== true ) {
10 return $p;
11 }
12
13 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
14 # with the addition that a leading '+' sign is ok. Note that leading zeros
15 # are fine, and will be left in the input, which is useful for things like
16 # phone numbers when you know that they are integers (the HTML5 type=tel
17 # input does not require its value to be numeric). If you want a tidier
18 # value to, eg, save in the DB, clean it up with intval().
19 if ( ! preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) )
20 ) {
21 return $this->msg( 'htmlform-int-invalid' )->parseAsBlock();
22 }
23
24 return true;
25 }
26 }