Javascript Bootstrap - Textarea count characters validation with example

Javascript Bootstrap - Textarea count characters validation with example

In this example, I will tell you how to implement character count and apply validation for maximum character length in textarea.

This is very useful to let you know how many characters you type into the field.

For example, for SMS field you know what limitation is required to send message by using SMS Api, there you can apply the max length validation.

You can customize the text message of remaining characters as well you can customize their position.

Bootstrap Maxlength is a very awesome jQuery plugin to validate character count on client side.

Let's have a example :

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Bootstrap Maxlength Validation with Example</title>
  5.     <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  6.     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  7.     <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  8.     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-maxlength/1.7.0/bootstrap-maxlength.min.js"></script>
  9. </head>
  10. <body>
  11. <div class="row">
  12. <div class="col-md-offset-3 col-md-6">
  13.         <div class="form-group">
  14.             <textarea class="form-control" placeholder="Type here to see how it work" maxlength="100"></textarea>
  15.         </div>
  16. </div>
  17. </div>
  18.     <script type="text/javascript">
  19.         $('textarea').maxlength({
  20. alwaysShow: true,
  21. });
  22.     </script>
  23. </body>
  24. </html>

Now we will change the position of counter at top left, you can place the counter indicator on top-right, bottom-left etc.

  1.     <script type="text/javascript">
  2.         $('textarea').maxlength({
  3. alwaysShow: true,    
  4.      placement: 'top-left'
  5. });
  6.     </script>

You can also customize the message by following way:

  1. <script type="text/javascript">
  2.         $('textarea').maxlength({
  3. alwaysShow: true,
  4.      threshold: 10,
  5.      warningClass: "label label-success",
  6.      limitReachedClass: "label label-danger",
  7.      separator: ' out of ',
  8.      preText: 'You write ',
  9.      postText: ' chars.',
  10.      validate: true,
  11.      placement: 'bottom-left'
  12. });
  13.     </script>

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort