Search code examples
javascriptinteger-overflow

Determine if conversion from string to 32-bit integer will overflow


Trying to do front-end validation on an HTML input instead of throwing an exception in the Java back-end.


Solution

  • if ((the_number >> 0) != the_number) {
      // overflow...
    }
    

    You still need a server-side check because the client-side may turn off Javascript, etc.