Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Comparing to the current best answer this code is more user-friendly - it allows usage of arrows, backspace, delete and other keys/combinations:</p> <pre><code>// Ensures that it is a number and stops the key press $('input[name="number"]').keydown(function(event) { if (!(!event.shiftKey //Disallow: any Shift+digit combination &amp;&amp; !(event.keyCode &lt; 48 || event.keyCode &gt; 57) //Disallow: everything but digits || !(event.keyCode &lt; 96 || event.keyCode &gt; 105) //Allow: numeric pad digits || event.keyCode == 46 // Allow: delete || event.keyCode == 8 // Allow: backspace || event.keyCode == 9 // Allow: tab || event.keyCode == 27 // Allow: escape || (event.keyCode == 65 &amp;&amp; (event.ctrlKey === true || event.metaKey === true)) // Allow: Ctrl+A || (event.keyCode == 67 &amp;&amp; (event.ctrlKey === true || event.metaKey === true)) // Allow: Ctrl+C //Uncommenting the next line allows Ctrl+V usage, but requires additional code from you to disallow pasting non-numeric symbols //|| (event.keyCode == 86 &amp;&amp; (event.ctrlKey === true || event.metaKey === true)) // Allow: Ctrl+Vpasting || (event.keyCode &gt;= 35 &amp;&amp; event.keyCode &lt;= 39) // Allow: Home, End )) { event.preventDefault(); } }); </code></pre> <p><strong>Notes:</strong> The <code>event.metaKey === true</code> is required for Mac users (thanks <a href="https://stackoverflow.com/users/1104780/ryanm">RyanM</a> for noticing this). Also if you uncomment Ctrl+V sequence you will need to write additional code for checking pasted text (disallow non-numeric symbols).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload