Character, Numeric, Character count validation for textbox using javascript in ASP.NET

Character, Numeric, Character count validation for textbox using javascript in ASP.NET

In this client side validation, we are doing username validation for the text box. Here I am checking characters, numerics and total characters count between 5 to 10 (/^[a-z,A-Z,0-9]{5,10}$/;).

If you want any other regular expressions please write in comments i will help you.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function ValidateForm() {
            var txtName = document.getElementById("txtName").value;
            var regularExpression = /^[a-z,A-Z,0-9]{5,10}$/;
            if (!txtName.match(regularExpression)) {
                alert("Name should be alpha numeric and characters count with in 5 to 10");            
            }
        }
    </script>
</head>
<body>
User Name: <input type="text" id="txtName" /><br />
<br />
<input type='button' value="validate" onclick="ValidateForm();" />

</body>
</html>


Before doing this operation you may need required field validation for textbox using javascript
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar