Trying to do front-end validation on an HTML input instead of throwing an exception in the Java back-end.
问问题
3357 次
3 回答
2
Check whether the number is more than 2147483647
.
For example:
if (parseInt(num, 10) > 2147483647)
//BAD!!!
于 2010-02-17T16:35:56.677 回答
1
if ((the_number >> 0) != the_number) {
// overflow...
}
You still need a server-side check because the client-side may turn off Javascript, etc.
于 2010-02-17T16:36:46.613 回答
0
Just check:
if (parseInt(myNumberAsString, 10) > 2147483647) { alert("Invalid int!"); }
于 2010-02-17T16:39:42.770 回答