Validation for CNIC number using jQuery in ASP.Net

Last Reply on Oct 04, 2016 02:27 AM By AnandM

Posted on Sep 22, 2016 01:54 AM

how to accept alphabets only in textbox in asp

Posted on Sep 22, 2016 02:20 AM

Hi AhmadCh,

Refer the below article.

Regular Expression (Regex) to accept only Alphabets and Space in TextBox in ASP.Net

Also i have created a sample which fullfill your requirement

HTML

<div>
    <input type="text" name="name" id="txtName" />
    <input type="button" value="Submit" id="btnSubmit" name="Submit" />
</div>
<div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('[id*=btnSubmit]').click(function () {
                var regex = /^[A-Za-z ]+$/;
                if (!regex.test($('[id*=txtName]').val())) {
                    alert('Please Enter Only Alphabets');
                    $('[id*=txtName]').val('');
                }
            });
        });
    
    </script>
</div>

Demo


Posted on Oct 04, 2016 02:27 AM Modified on on Oct 04, 2016 02:28 AM

Hi AhmadCh,

Please refer below sample 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('[id*=txtRic]').mask('00000-0000000-0');
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="text" name="txtRic" id="txtRic" />
    </div>
    </form>
</body>
</html>

Demo