limit textbox characters using jquery

Jquery is best for client side operations. so this is simple snippet provided by Asp.net MVC Snippets to you which restrict text boxes on specific characters

Create a new project in visual studio and make a simple ActionController and its corresponding view

View Code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var limit = 50;
$('textarea[id$=numbers]').keyup(function() {
var lenn = $(this).val().length;
if (lenn > limit) {
this.value = this.value.substring(0, limit);
}
$('#leftchar').text(limit - len + " characters left");
});
});
</script>

<h2>50 characters allow</h2>
<input type="text" id="numbers"> 
<span id="leftchar"></span>

For more jquery snippets please visit Jquery section