jQuery CKEditor Validation Example with demo

Today, We want to share with you jQuery CKEditor Validation.In this post we will show you Ckeditor required field validation example in Jquery, hear for Validate CKEditor Fields Using JQuery we will give you demo and example for implement.In this post, we will learn about ckeditor required field validation with an example.

jQuery CKEditor Validation

There are the Following The simple About jQuery CKEditor Validation Full Information With Example and source code.

As I will cover this Post with live Working example to develop Validate CKEditor Using jQuery Validate, so the some major files and Directory structures for this example is following below.

Required field validation ckedito

ckeditor cdn

First if all You include jQuery as well as ckeditor CDN in Your Project.

  • JQuery-2.2.4.js
  • JQuery.Validate.js
  • CKEditor.js

We have HTML Source code like –

<form id="product_img">   
	<p> 
		<label>Image<span class='required'>*</span></label> 
		<span class="field"> 
		<textarea  name="ckproduct_img" id="ckproduct_img"></textarea> 
		</span> 
	</p> 
	<input type="submit" value="submit">  
</form>

I applied CKEditor on above textarea name as ckproduct_img –

SCRIPT FOR CKEDITOR

var obj  = { 
	stylesSet : [ 
	{name: 'Align Left', element: ['p','h1','h2','h3','h4','h5','h6','td','th','div','ul','ol','li','table','img'], attributes: {'class': 'text-left'}}, 
	contentsCss  : ['/assets/admin/css/custom.css'], 
	allowedContent:true, 
	removeButtons :  JustifyLeft
};
CKEDITOR.replace('ckproduct_img', obj); 

SCRIPT FOR jQuery VALIDATION

jQuery.validator.addMethod('ckrequired', function (value, element, params) { 
	var idname = jQuery(element).attr('id'); 
	var messageLength =  jQuery.trim ( CKEDITOR.instances[idname].getData() ); 
	return messageLength.length !== 0; 
}, "Image field is required"); 

Then write the validation rule for the text area as –

jQuery("#product_img").validate({ 
ignore: [], 
rules: { 
	ckproduct_img: { 
	ckrequired: true 
	} 
}, 
messages: {         
	ckproduct_img: { 
	ckrequired : "Please select an Any image required" 
	}
} 
});

Including a default text in CKEditor

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Ckeditor required field validation example in Jquery</title>
        <script src="ckeditor/ckeditor.js"></script>
    </head>
    <body>
	<h1>ckeditor 4 Examples</h1>
        <form>
        <textarea id="liveEditor" name="liveEditor" id="liveEditor"> 
			<b>Introduction</b>
			<p> pakainfo is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development. We deliver the useful and best tutorials for web professionals β€” developers, programmers, freelancers and site owners. Any visitors of this site are free to browse our tutorials, live demos and download scripts.
			<br />
			<b> Conclusion </b>
	    </textarea>
			<script type="text/javascript">
				CKEDITOR.replace('liveEditor');
			</script>
        </form>
    </body>
</html>

how to use ckeditor in php

simple add or embed CKEditor in php page

Also Read This πŸ‘‰   PHP artisan dump-autoload Fix "class not found"

<?php
    include("ckeditor/ckeditor.php");
    $CKeditor = new CKeditor();
    $CKeditor->BasePath = 'ckeditor/';
    $CKeditor->editor('editor1');
?>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about jQuery CKEditor Validation.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.