mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
This might be simple, but I can't find the way.

I need to validate if certain Input is an Integer number ($$2 in this case)

Code:
...
if ( $$2 !=/isNot IntegerNumer ) { halt }  
or smthng like
if ( $$2 !$isInt ) { halt }   <- hehe you get the point
...


$$2 = sd8df34f <-- would halt
$$2 = 300 <-- OK

Thanks.


Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
  • if ($int($2) == $2) { ? }

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
if $2 isnum && $int($2) == $2 {
  ;what you want to happen if it is an integer
}
else {
  return
}


Using return in a script is normally preferable to using halt, as halt can prevent other scripts from executing even if you want them to

Joined: Feb 2005
Posts: 342
R
Fjord artisan
Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Code:
alias num {
  if ($1 isnum) {
    var %d = $iif($count($1,.) == 1,1,0)
    if (!$prop && %s) { return $true }
    if ($prop == int && !%d) { return $true }
    if ($prop == dec && %d) { return $true }
  }
  elseif ($prop == hex && $regex($1,/^[0-9a-f]+$/i)) { return $true }
  return $false
}


$num(), returns $true if: The first param is a number/decimal.
$num().int, returns $true if the first param is an INT.
$num().dec, returns $true if there is a decimal, and only one decimal.
$num().hex, returns $true if the characters stay between 0 and F.

Note: It's false if there's two decimals. This is just an example of how you could check for these.

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
there's a lot of ways to check this, heres a couple ive used in codesize challenges in the past

Code:
if (1 // $2)


the simplest, but allows $2 = 1.0, $2 = +3 and such

Code:
if (1 // + $+ $2.)


now $2 can only be an exact integer with no leading + or .0

Code:
if ($2. isnum x-y)


$2 is an integer in the range x-y, i guess this was an obvious example though ;D




"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
Got it working thanks to you guys

Thanks smile


Link Copied to Clipboard