Code 101: Characters, Letters, and Word Counter Another program I found in my college notebook. This program can be used as a counter for your post or article, counting the characters, letters, words, special characters, and digits in the text area. Here's the code, check and test it. Live Demo: https://codepen.io/mihsaky/pen/MWogdzK Note: The program can also count the sentence and a paragraph. Because there is a problem with counting, I just make it a comment status (hide). If you want to try it, remove the "<!--" and "-- >" in HTML code and the "//" in Javascript code. HTML code <html> <head> <title>Click@Code</title> </head> <body> <h3>Characters, Letters and Word Counter</h3> <div style="color:#333; font-weight:bold;"> <span class="lnr lnr-keyboard"></span> Write something...<br> <br> </div> <div class="form-holder"> <textarea id="countAll" placeholder="" style="height:130px; width:100%; line-height: 15px; resize: vertical;"></textarea> </div> <h4 id="answer">Result:</h4> <div id="demo" style="text-align:justify; color:#666; background-color: #eee; border: 1px solid #999; padding: 8px; overflow-y:scroll; height:285px;"> <!-- <p id="parCount">0 Paragraph</p> --> <!-- <p id="sentCount">0 - Sentence</p> --> <p id="wordCount">0 - Word</p> <p id="vowelCount">0 - Vowel</p> <p id="conCount">0 - Consonant</p> <p id="specialCount">0 - Special Character</p> <p id="digitCount">0 - Digit</p> <p id="charNumWithSpace">0 - Character with space</p> <p id="charNumWithOutSpace">0 - Character without space</p> </div> </body> </html> Javascript Code $(document).ready(function() { $('#countAll').keyup(function() { var count = $('#countAll').val(); var withSpace = count.length; // Without using regex //var withOutSpace = $('#countAll').value.split(' ').join('').length; //with using Regex var withOutSpace = count.replace(/\s+/g, '').length; var wordsCount = count.match(/\S+/g).length; var vowelsCount = count.split(/[aeiou]/g).length - 1; var consCount = count.split(/[bcdfghjklmnpqrstvwxyz]/g).length - 1; var digitsCount = count.replace(/[^0-9]/g, '').length; var specialsCount = count.split(/[@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/g).length - 1; //var senteCount = count.split(/[.?!]/g).length - 1; //var parsCount = count.split(/\n *\n/).length; //$('#parCount').html('<b>' + parsCount + '</b> - Paragraph(s)'); //$('#sentCount').html('<b>' + senteCount + '</b> - Sentence(s)'); $('#vowelCount').html('<b>' + vowelsCount + '</b> - Vowel(s)'); $('#conCount').html('<b>' + consCount + '</b> - Consonant(s)'); $('#wordCount').html('<b>' + wordsCount + '</b> - Word(s)'); $('#specialCount').html('<b>' + specialsCount + '</b> - Special Character(s)'); $('#digitCount').html('<b>' + digitsCount + '</b> - Digit(s)'); $('#charNumWithSpace').html('<b>' + withSpace + '</b> - Character(s) with space'); $('#charNumWithOutSpace').html('<b>' + withOutSpace + '</b> - Character(s) without space'); }); });
Log in to join in Reading is open to everyone. Replying needs an account.
1 comment
Sumakit ulo ko bigla hahahahaha🤧