Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Tools
    • Json Beautifier
    • Html Beautifier
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
14 Aug
2022

Alphabet validation using JavaScript

by Shubham Batra

1023

So, for applying alphabet only validation in js we will use onkeypress event of input boxes. So you can check the below code for applying the validation.

Below is a code in HTML and JavaScript to alphabet validate a text field

<form>
    <div class="form-group row">
        <label for="inputPassword" class="col-sm-2 col-form-label">Enter Only Alphabets</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="inputAlphabet" placeholder="Enter Only Alphabets" value="" name="inputAlphabet" onkeypress="return onlyAlphabets(event)" />
        </div>
    </div>
</form>

Here is how to validate the input only to accept alphabet this will only take alphabet values like "abcc". We are checking event keycodes for checking if the entered character is a valid one.

<script>
    function onlyAlphabets(evt) {
        try {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
                return true;
            else
                return false;
        }
        catch (err) {
            alert(err.Description);
        }
    }
</script>

You can copy complete code from here .

<form>
    <div class="form-group row">
        <label for="inputPassword" class="col-sm-2 col-form-label">Enter Only Alphabets</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="inputAlphabet" placeholder="Enter Only Alphabets" value="" name="inputAlphabet" onkeypress="return onlyAlphabets(event)" />
        </div>
    </div>
</form>
<script>
    function onlyAlphabets(evt) {
        try {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123))
                return true;
            else
                return false;
        }
        catch (err) {
            alert(err.Description);
        }
    }
</script>

So, this is how you can apply alphabet only validation using javascript.

  • |
  • Alphabets validation javascript , Allow only Alphabets to be typed in a textbox , Alphabets validation in JavaScript , Aphabet validations using js

Comments

Follow Us On Social Media - Like Us On Facebook

Best Sellers

product 1

Hand Hug Bracelet For Women Men Cuff Bangle Adjustable Lover Couple Bracelets

Can be given as a gift to your family, relatives, or friends

Buy $15.99
product 1

Teddy bear hug bear plush toy bear cub

Can be given as a gift to your family, relatives, or friends


Buy $49.99

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Thank you for Downloading....!

Subscribe for more tutorials

Support our team

Continue with Downloading

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2023 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier