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.
Some of my previous mvc articles are as follows:
Display
No of Characters Entered In TextArea Using jQuery, How
to Create and Read Cookies In ASP.NET Using C#, Multiple
File Upload With Asp.Net MVC C# and HTML5 | How to upload files to ASP.NET MVC
application, How
to get a User's Client IP address in ASP.NET using C#.Net, Drag
Drop Cells in GridView Control Using Asp.net C# and jQuery, Multiple
File Upload With Asp.Net MVC C# and HTML5 | How to upload files to ASP.NET MVC
application, Display
Alert Message on Page Load in MVC Application Using Javasscript.
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
0 comments:
Please let me know your view