HTML text input allow only numeric input

Note: This is an updated answer. Comments below refer to an old version which messed around with keycodes. JavaScript Try it yourself on JSFiddle. You can filter the input values of a text <input> with the following setInputFilter function (supports Copy+Paste, Drag+Drop, keyboard shortcuts, context menu operations, non-typeable keys, the caret position, different keyboard layouts, … Read more

Tainted canvases may not be exported

For security reasons, your local drive is declared to be “other-domain” and will taint the canvas. (That’s because your most sensitive info is likely on your local drive!). While testing try these workarounds: Put all page related files (.html, .jpg, .js, .css, etc) on your desktop (not in sub-folders). Post your images to a site … Read more

Is it possible to stop JavaScript execution?

Short answer: If you want to know more, keep reading. Do you want to stop JavaScript’s execution for developing/debugging? The expression debugger; in your code, will halt the page execution, and then your browser’s developer tools will allow you to review the state of your page at the moment it was frozen. Do you want … Read more

Initializing an Array with a Single Value

no initialization (that i know of) Update Since ever posting this answer 4 years ago, people seem to keep coming back here for this answer. For benchmarking purposes I made a JSPerf with some different solutions. The solution above here isn’t the quickest, although it’s short. To stick to the same short style, but with … Read more

How can I check if a string is a valid number?

2nd October 2020: note that many bare-bones approaches are fraught with subtle bugs (eg. whitespace, implicit partial parsing, radix, coercion of arrays etc.) that many of the answers here fail to take into account. The following implementation might work for you, but note that it does not cater for number separators other than the decimal … Read more