Always indent the continuation one level deeper, and always place the closing parenthesis on the next line, per coding conventions. https://www.mediawiki.org/wiki/Manual:Coding_conventions#Indenting_and_alignment https://www.mediawiki.org/wiki/Manual:Coding_conventions#Line_continuation Regexp used: (\t+)(if|while|\} elseif|foreach).+(?<![;}])\n\1\S Also: * Change to just one line if line length stays under 100 characters. * Add "// Do nothing" comment in empty 'if' bodies. * Change '#' comments to '//' comments near affected code. Change-Id: I4f62658fddb5a0ed18bbf9b2231cd794683d6402
26 lines
818 B
PHP
26 lines
818 B
PHP
<?php
|
|
|
|
/**
|
|
* A field that must contain a number
|
|
*/
|
|
class HTMLIntField extends HTMLFloatField {
|
|
function validate( $value, $alldata ) {
|
|
$p = parent::validate( $value, $alldata );
|
|
|
|
if ( $p !== true ) {
|
|
return $p;
|
|
}
|
|
|
|
# http://dev.w3.org/html5/spec/common-microsyntaxes.html#signed-integers
|
|
# with the addition that a leading '+' sign is ok. Note that leading zeros
|
|
# are fine, and will be left in the input, which is useful for things like
|
|
# phone numbers when you know that they are integers (the HTML5 type=tel
|
|
# input does not require its value to be numeric). If you want a tidier
|
|
# value to, eg, save in the DB, clean it up with intval().
|
|
if ( !preg_match( '/^((\+|\-)?\d+)?$/', trim( $value ) ) ) {
|
|
return $this->msg( 'htmlform-int-invalid' )->parseAsBlock();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|