[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/htmlform/ -> HTMLIntField.php (source)

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


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1