How To: Limit Input Box Characters To Defined Count Using jQuery

Earlier today working on a project , I found one trick which I would like to share. Here is a small code that limit a input box for defined number of characters.

Please take a look on following example:


<input id="myInput" value=""/>


Jquery snippet

Assuming we have to limit characters to 20.

	$('#myInput').keyup( function() {
		var $this = $(this);
		if($this.val().length > 20)
			$this.val($this.val().substr(0, 20));			


That’s it, yeah its done!! You can check Working Demo

Any updations, suggestions and corrections are welcome.

Recently Published


10 Best HTML5 Frameworks For Hybrid App Development

Hybrid apps are generally built around native web view container or ...


A Look at The Evolution Of WordPress and What Future Holds For It

When it comes to developing a website, WordPress is the first name ...


7 WordPress Plugins That Make Your Site Mobile Responsive

Not much in the recent past, having a responsive website that works ...


Things you should Consider When You Are Designing an E-commerce Website

The people of today’s generation have discovered the various ...


Developing a Mobile App Using Open Source Software? Consider These Tips For Security

Today, almost every IT organization (including the Fortune 500 ...


5 CSS Tools You Shouldn’t Miss As a Web Designer and Developer

It’s no secret that CSS (Cascading Style Sheets) is the key to ...


10 Awesome Live Chat Plugins for WordPress

Patronage by loyal customers yields 65 percent of a typical ...


10 High-Grade Premium Drupal Themes Worth A Quick Install

Serving as the perfect tools for enhancing your Drupal ...


A Comprehensive Guide For Setting Up Magento 2

The much speculated beta version of the Magento 2 has been finally ...