Alphabets Validation on textbox in JS onkeypress : JS onkeypress में टेक्स्टबॉक्स पर अक्षर सत्यापन

Alphabets Validation on Textbox in jQuery

In this example, alphabet validation in Javascript “onkeypress” event to accept alphabets only (इस उदाहरण में, जावास्क्रिप्ट में वर्णमाला सत्यापन “onkeypress” इवेंट केवल वर्णमाला को स्वीकार करने के लिए है).

Alphabets Validation on textbox in JS onkeypress
  • The onkeypress=”return onlyAlphabetsAccept(event,this);” function called in text box on onkeypress event.
  • The charCode checks ASCII code of keys from keyboard (charCode कीबोर्ड से कुंजियों के ASCII कोड की जाँच करता है).
  • No need for any jQuery library (किसी jQuery लाइब्रेरी की आवश्यकता नहीं).
<!DOCTYPE html>
<html>
    <head>
    <script type="text/javascript">
    function onlyAlphabetsAccept(e, t) {
        try {
            if (window.event) { var charCode = window.event.keyCode; }
            else if (e) { var charCode = e.which; }
            else { return true; }
            if ((charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 123) && charCode != 32 && charCode != 8 && charCode != 46) {
                return false;
            }
            return true;
        }
        catch (err) { alert(err.Description); }
    }
    </script>
   </head>
	<body>

     <input type="text" onkeypress="return onlyAlphabetsAccept(event,this);" name="studentname">

	</body>
</html>

Email Validation onblur in JavaScript …

Alphabets Validation on textbox in JS onkeypress

Tags: Alphabet validation using JavaScript, Alphabets Validation on textbox in JS onkeypress, How to allow only alphabets in input in JavaScript, Javascript Function to enter only alphabets on keypress

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *