connectseekers.com

Sunday, 15 June 2014

Restrict Number of Characters to be Entered in the TextArea Using jQuery in Asp.Net MVC

6/15/2014 - By Pranav Singh 0

In this article I will tell you how you can restrict user to add only restricted no of character in an TextArea in you mvc2/mvc3/mvc4/mvc5 application using jquery.  This article will show you Restrict Number of Characters to be Entered in the TextArea Using jQuery.


hbgSo for this article first we will create a new  mvc application add the below code.

@{
    ViewBag.Title = "Restrict Number of Characters to be Entered in the TextArea Using jQuery";
}
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
  
    <script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script>
        function ValidateCharactercount(val) {
            var len = val.value.length;
            if (len >= 20) {
                val.value = val.value.substring(0, 20);
            } else {
                $('#divmessage').text(20 - len);
            }
        };
    </script>
    @Html.TextArea("TextArea", "", new { @id = "txtdata", @onkeyup = "javascript:ValidateCharactercount(this);", @rows = 5,@cols=30 })
    <div id="divmessage" style="color: Red;">
    </div>
}

Now run the application


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