Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>JavaScript</strong> (the most reliable still)</p> <p>While this is simple, it will not let you use combination keys and other non-typeable keys. For a complete JavaScript solution that also supports input of type number and max length validation, consider using <a href="https://gist.github.com/nbouvrette/84ef4f498ac06cdd5b60" rel="noreferrer">this Polyfill</a>.</p> <p><strong>HTML 5</strong> with <code>&lt;!DOCTYPE html&gt;</code> has <a href="https://www.w3.org/TR/html/sec-forms.html#number-state-typenumber" rel="noreferrer">native solution</a>:</p> <p><code>&lt;input type="number"&gt;</code></p> <p>Beware that it <a href="http://caniuse.com/#feat=input-number" rel="noreferrer">does not behave in a standard way in some browsers</a>.</p> <p>Try <a href="http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_number" rel="noreferrer">input type=number</a> to see the HTML5 version in action.</p> <p>See also <a href="https://github.com/jonstipe/number-polyfill" rel="noreferrer">https://github.com/jonstipe/number-polyfill</a> for transparent support in older browsers.</p> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function() { $("#txtboxToFilter").keydown(function (e) { // Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || // Allow: Ctrl/cmd+A (e.keyCode == 65 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: Ctrl/cmd+C (e.keyCode == 67 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: Ctrl/cmd+X (e.keyCode == 88 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: home, end, left, right (e.keyCode &gt;= 35 &amp;&amp; e.keyCode &lt;= 39)) { // let it happen, don't do anything return; } // Ensure that it is a number and stop the keypress if ((e.shiftKey || (e.keyCode &lt; 48 || e.keyCode &gt; 57)) &amp;&amp; (e.keyCode &lt; 96 || e.keyCode &gt; 105)) { e.preventDefault(); } }); }); </code></pre> <p><strong>More complex validation options</strong></p> <p>If you want to do some other validation bits and pieces, this could be handy:</p> <p><a href="http://www.javascript-coder.com/html-form/javascript-form-validation.phtml" rel="noreferrer">http://www.javascript-coder.com/html-form/javascript-form-validation.phtml</a> <a href="https://github.com/lockevn/html-numeric-input" rel="noreferrer">https://github.com/lockevn/html-numeric-input</a></p> <p><strong>But don't forget you still <em>must</em> do server side validation!</strong></p> <p>for AZERTY keyboard:</p> <p><strong>jQuery</strong></p> <pre><code>// Allow: backspace, delete, tab, escape, enter and . if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || // Allow: Ctrl+A (e.keyCode == 65 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: Ctrl+C (e.keyCode == 67 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: Ctrl+X (e.keyCode == 88 &amp;&amp; (e.ctrlKey === true || e.metaKey === true)) || // Allow: home, end, left, right (e.keyCode &gt;= 35 &amp;&amp; e.keyCode &lt;= 39) || //Allow numbers and numbers + shift key ((e.shiftKey &amp;&amp; (e.keyCode &gt;= 48 &amp;&amp; e.keyCode &lt;= 57)) || (e.keyCode &gt;= 96 &amp;&amp; e.keyCode &lt;= 105))) { // let it happen, don't do anything return; } // Ensure that it is a number and stop the keypress if ((!e.shiftKey &amp;&amp; (e.keyCode &lt; 48 || e.keyCode &gt; 57)) || (e.keyCode &lt; 96 || e.keyCode &gt; 105)) { e.preventDefault(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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