Skip to content

Commit

Permalink
Refactored isNotValid method
Browse files Browse the repository at this point in the history
  • Loading branch information
stoneC0der committed Jan 26, 2020
1 parent 6e285f2 commit ed2cc1d
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/ShortenNums.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ private static function notSupported($value): string
private static function isNotValid($value)
{
// Accept only integers and string with valid integers.
if (!is_int((int)$value))
if (!is_int((int)$value) || !preg_match('/((?!(0))^[\d]+)$/i', (string)$value))
throw new \Exception("TypeError: $value is not a valid integer", 1);
// Should not start with 0. Also check the number length
if (!preg_match('/((?!(0))^[\d]+)$/i', (string)$value))
throw new \Exception("Error: $value is not valid, value should not start with 0", 1);
// TODO: Allow negative numbers
if (($value < 999) || ($value > 999999999999000)) {
return true;
Expand Down

0 comments on commit ed2cc1d

Please sign in to comment.