Skip to content
Advertisement

How can I limit the max value of number?

I want to secure my page by checking if the value is digital (0,1,2,3) and if it is in the range from 0 to 120. I think ctype_digit function limits numbers, so can not be passed any negative number. How can I limit the max value in the simplest way?

JavaScript

I was thinkig about intval but it can pass negative numbers.

Advertisement

Answer

JavaScript

Basically this says “If it’s not a number or if it’s larger than 120, stop”

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement