connectseekers.com

Sunday, 15 June 2014

Allow Only Alphabets in TextBox Using Javascript in Asp.Net

6/15/2014 - By Pranav Singh 0

In this article I will show you how you can restrict user to allow only enter alphabet in a text box using javascript in your asp.net application.


So for this article first we will create a new asp.net application add the below code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AllowCharactorOnly.aspx.cs"
    Inherits="ProjectDemo_Asp.et.AllowCharactorOnly" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Allow Only Alphabets in TextBox Using Javascript in Asp.Net</title>
    <script language="javascript">
        function onlyAlphabets() {
            var regex = /^[a-zA-Z]*$/;
            if (regex.test(document.getElementById("txtdetail").value)) {
                return true;
            } else {
                alert("Alphabets Only Please.");
                return false;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtdetail" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Submit"
            OnClientClick="javascript:return onlyAlphabets();" onclick="Button1_Click"/>
        <br />
        <asp:Label ID="lblmessage" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

I have added code to verify the pages have been submitted.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectDemo_Asp.et
{
    public partial class AllowCharactorOnly : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            lblmessage.Text = "Form submitted.";
        }
    }
}

Now run the application


DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top