<!DOCTYPE html> <html> <body> <input type="text" onkeyup = "this.value=parseInt(this.value,10) || 0"> </body> </html>