MediaWiki  REL1_24
HTMLIntField.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLIntField extends HTMLFloatField {
00007     function validate( $value, $alldata ) {
00008         $p = parent::validate( $value, $alldata );
00009 
00010         if ( $p !== true ) {
00011             return $p;
00012         }
00013 
00014         # http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
00015         # with the addition that a leading '+' sign is ok. Note that leading zeros
00016         # are fine, and will be left in the input, which is useful for things like
00017         # phone numbers when you know that they are integers (the HTML5 type=tel
00018         # input does not require its value to be numeric).  If you want a tidier
00019         # value to, eg, save in the DB, clean it up with intval().
00020         if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) )
00021         ) {
00022             return $this->msg( 'htmlform-int-invalid' )->parseAsBlock();
00023         }
00024 
00025         return true;
00026     }
00027 }