How to required validation in Ckeditor field in Jquery?

Today now in this post i will show you How to required validation in Ckeditor field in Jquery? If we want then we can easily add required field validation easily by using jquery. If we are using textbox, textarea thrn we can easily make validation. But When we are using ckeditor then it’s not so simple.

So now in this example i will give you e example of how to add Ckeditor required field validation in javascript.

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>

Read Also : Laravel 8 Mobile Number Verification Tutorial

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →