Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone returning same keydown event for (hash and 3) and (Asterisk and 8)
    text
    copied!<p>Am working on phone validation and have a requirement of auto formatting the input with phone no and only allow numeric characters to be added . However when i try to restrict the input using keydown and keypress, IPhone is allowing me to enter # and * . When i checked the keydown value , they both are same with 3 and 8 respectively (keycode 51 and 56). This works perfectly in Android browsers but fails in iPhone.</p> <p>Anyone faced similar issue.</p> <pre class="lang-js prettyprint-override"><code>$(formSelector + ' input[name^="phone"]').on('keydown keypress',function (e) { // Allow: backspace, delete, tab, escape, and enter if ( e.keyCode == 46 || e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 27 || e.keyCode == 13 || // Allow: Ctrl+A (e.keyCode == 65 &amp;&amp; e.ctrlKey === true) || // Allow: home, end, left, right (e.keyCode &gt;= 35 &amp;&amp; e.keyCode &lt;= 39) ) { // let it happen, don't do anything return; } else { // 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>I also tried one other method which was suggested in stackoverflow to bind input with 'input propertychange' events and then use pattern matching. but this works correct in IPhone , but fails in Android.</p> <pre class="lang-js prettyprint-override"><code>$(formSelector + ' input[name^="phone"]').bind('input propertychange', function() { var text = $(this).val(); if (isNaN(text)) { $(this).val(text.replace(/[^\d]/gi, '')); } }); </code></pre> <p>Does anyone have a common solution for this problem ??</p> <p>Thank you in advance</p>
 

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