waNumberValidator

Contents...

Methods

  • isValid

    Checks whether a specified value represents a number.

public function isValid ($value)

Checks whether a specified value represents a number. The following types of values are considered containing numbers:

  • integers including those with a leading “minus” (-) character without a whitespace;
  • decimal fractions (with a decimal point or comma) including those with a leading “minus” (-) character without a whitespace.

Parameters

  • $value

    Value which needs to be checked whether it represents a number.

Example

    $validator = new waNumberValidator();
    
    wa_dumpc(
        $validator->isValid('12'),     // true
        $validator->isValid('-12'),    // true
        $validator->isValid('12,34'),  // true
        $validator->isValid('12.34')   // true
    );
    
    wa_dumpc(
        $validator->isValid(' 12'),     // false
        $validator->isValid('- 12'),    // false
        $validator->isValid('12,34 '),  // false
        $validator->isValid('a12.34z')  // false
    );