<< |
>>
#5277 Dodano: 04-09-2011 11:24. Głosów: 276
I want to check if a number is negative. I'm searching for the easiest way, so a predefined javascript function would be the best but I didn't found yet anything, here is what I have so far but I don't think that this is a good way:
function negative(number) {
if (number.match(/^-\d+$/)) {
return true;
} else {
return false;
}
}
Odpowiedź:
Instead of writing a function to do this check, you should just be able to use this expression:
(number < 0)
http://stackoverflow.com/questions/3571717/javascript-negative-number
<< |
>>
function negative(number) {
if (number.match(/^-\d+$/)) {
return true;
} else {
return false;
}
}
Odpowiedź:
Instead of writing a function to do this check, you should just be able to use this expression:
(number < 0)
http://stackoverflow.com/questions/3571717/javascript-negative-number