jQuery way to limit input characters using javascript substring function
It’s an example of useful jQuery way to limit user entering a maximum set number of character in your input fields. Example makes use of javascript substring function to limit user upto 20 character which is triggered on keyup event. It truncate anything extra to that limit.
$("input[name=Title]").keyup(function(){
var text = $(this).val();
if(text.length > 20) {
text = text.substring(0, 20);
$(this).val(text);
}
})
Possibly Related posts:
- Limitation on the number of characters in jquery ajax response
The following jquery ajax call would return approx. 8442 characters in its “html” response. Content exceeding this number would be truncated. var url = "load_pocket_fabrics.php?filter="... - Useful trim prototype (function) in core javascript
Below is the most commonly used trim prototype/function in javascript. Posting for reference. String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,"") } You can place the above... - Sum of values in input fields grouped by class attribute using jQeury
Here is the jQuery way to calculate the sum of all values stored in input fields grouped by class “.subtotal”. In this example the sum... - Browser detect script in javascript
I found this useful and up-to-date article to detect browser in JavaScript. Please refer to the author’s site page for detailed explanation. The site (http://www.quirksmode.org/)... - A simple javascript image slide show using setTimeout and jQuery
Just now i created a small slideshow. The slideshow uses some static images stored in a javascript object (array) and runs till the last image...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.





