I needed a character counter for making sure my client uses the Yoast recommended amount of characters for socials shares and search results. He understands SEO gubbins is important but, every time he wrote a post with my advice in mind, he failed miserably.
So I figured I'd have to literally force him to comply with standards for his own good.
One part of that was making sure he writes his excerpts to the correct specifications.
This is only a minor change to Formidable's Word Counter, but it works well and achieves the goal.
jQuery(document).ready(function($){ $('#field_i1hy1').keyup(function(){ var s = this.value; s = s.replace(/(^s*)|(s*$)/gi,""); s = s.replace(/[ ]{2,}/gi," "); s = s.replace(/n /,"n"); s = s.replace(' ', '') document.getElementById("frm_field_16168_container").innerHTML = (s.split('').length) + ' characters used'; }); });
Used with html5's min length and max length, you can ensure a certain amount of characters are submitted though a field in the form.