The easiest way to achieve this is to use jQuery on the client side to handle this validation. There are a number of ways you can achieve this, though one of the easiest would be to use a ready made solution of which one can be found HERE
You’ll need to download the plugin file and include it within your header.php file like so;
<script type="text/javascript" src="https://wordpress.stackexchange.com/questions/54150/<?php bloginfo("template_directory');?>/js/charCount.js"/></script>
Directly beneath the above line you will then place the following;
<script type="text/javascript">
jQuery(document).ready(function(){
//custom usage
$("#txtTweet").charCount({
allowed: 500,
minChar: 15,
warning: 20,
counterText: 'Characters left: ',
disableControl: '#btnSubmit',
isDisable: true // is the control disable or not
});
});
</script>
Make sure that the above snippets of code are placed within your;
<head>
// usual head stuff here
<?php wp_head();?>
// include the charCount.js
// include the custom usage snippet
</head>
The reason you include your files after wp_head
is that this function will usually output your jQuery.js
file which needs to be declared before your charCount.js
and custom code to work correctly.
That link again is HERE – for which you can see a working demonstration.