Ckeditor required field validation example in Jquery

By Hardik Savani | June 11, 2016 | | 62872 Viewer | Category : Javascript jQuery


we can add required field validation easily using jquery if we have textbox, textarea, select box etc, but if we used ckeditor then it's not simple. In this example i give you how to add Ckeditor required field validation in javascript. we can do it using CKEDITOR.instances, so if you also require then you can use it.

Example:

<html lang="en">

<head>

<title>Jquery - ckeditor required field validation</title>

<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>

<script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js"></script>

</head>

<body>


<div class="container text-center">

<form>

<textarea name="editor"></textarea>

<button>Submit</button>

</form>

<script>

CKEDITOR.replace( 'editor' );

$("form").submit( function(e) {

var messageLength = CKEDITOR.instances['editor'].getData().replace(/<[^>]*>/gi, '').length;

if( !messageLength ) {

alert( 'Please enter a message' );

e.preventDefault();

}

});

</script>

</div>


</body>

</html>



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.


We are Recommending you: