Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Function to enter only alphabets on keypress
    primarykey
    data
    text
    <p>I want to enter only character values inside a <code>&lt;textarea&gt;</code> and numeric values in another. I have been able to make a JavaScript function which only allows numeric values to be entered in the <code>&lt;textarea&gt;</code> using <code>onkeypress</code>. This works in Firefox and Chrome.</p> <p>For alphabets I am creating another JavaScript function using <code>windows.event</code> property. Only problem is this works only in Chrome and not in Firefox.</p> <p>I want to know how to allow only alphabets to be entered using <code>onkeypress</code> event as used for entering only numeric values?</p> <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function isNumberKey(evt){ &lt;!--Function to accept only numeric values--&gt; //var e = evt || window.event; var charCode = (evt.which) ? evt.which : evt.keyCode if (charCode != 46 &amp;&amp; charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) return false; return true; } function ValidateAlpha(evt) { var keyCode = (evt.which) ? evt.which : evt.keyCode if ((keyCode &lt; 65 || keyCode &gt; 90) &amp;&amp; (keyCode &lt; 97 || keyCode &gt; 123) &amp;&amp; keyCode != 32) return false; return true; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;label for="cname" class="label"&gt;The Risk Cluster Name&lt;/label&gt; &lt;textarea id="cname" rows="1px" cols="20px" style="resize:none" placeholder="Cluster Name" onKeyPress="return ValidateAlpha(event);"&gt;&lt;/textarea&gt; &lt;br&gt; &lt;label for="cnum"&gt;Risk Cluster Number:&lt;/label&gt; &lt;textarea id="cmun" rows="1px" cols="12px" style="resize:none" placeholder="Cluster Number" onkeypress="return isNumberKey(event)"&gt;&lt;/textarea&gt;</code></pre> </div> </div> </p>
    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.
 

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