views:

39

answers:

1

I'm using the ckeditor 3.4 as text editor for my website, and want to validate the data at client side first, before submitting the data to server.

I can get the data of editor by using this code: var editorData = CKEDITOR.instances.editor1.getData();

but having trouble to validate data. The problem is: - The data should be invalid if user didn't enter anything into editor or enter only some space or line break (null data)

by default, CKEDITOR.instances.editor1.getData() return <br /> if user didn't type anything and return

<p>
 &nbsp;</p>
<br />

if user enter a line break (may be many <p>&nbsp;</p> if user enter many line break)

please help me to check this case should be invalid (null data) both at client side (js - jquery 1.4.2) and server side (php 5)?

thanks

+1  A: 

Look up http://stackoverflow.com/questions/154059/what-is-the-best-way-to-check-for-an-empty-string-in-javascript

Specifically:

var str = $('<p> &nbsp;</p> <br />').text();
if(str.replace(/\s/g,"") == ""){
}
Petah
how to check this: '<p>  </p><br />'
mana
@mana, check the updated answer
Petah
I have tried jquery validate plugin and it works. the problem now is
mana
@mana now is.....?
Petah