Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何设置CKEditor5 textarea不能为空?_Javascript_Php_Jquery_Html_Ckeditor5 - Fatal编程技术网

Javascript 如何设置CKEditor5 textarea不能为空?

Javascript 如何设置CKEditor5 textarea不能为空?,javascript,php,jquery,html,ckeditor5,Javascript,Php,Jquery,Html,Ckeditor5,我现在正在使用CKEditor5 文本区是: <textarea class="form-control" name="post_content" rows="10" cols="30" id="editor"></textarea> 但是,我仍然能够向数据库发送空内容 因为即使我提交了一个空内容,它也会向数据库发送一些html标记 在数据库中,我可以看到有html标记存储在列单元格中,如 <p></p> 它取决于使用CKEditor输入时

我现在正在使用CKEditor5

文本区是:

<textarea class="form-control" name="post_content" rows="10" cols="30" id="editor"></textarea>
但是,我仍然能够向数据库发送空内容

因为即使我提交了一个空内容,它也会向数据库发送一些html标记

在数据库中,我可以看到有html标记存储在列单元格中,如

<p></p>

它取决于使用CKEditor输入时的字体样式。它也可以是


还有其他方法可以解决这个问题吗?

也有同样的问题,提出了以下建议:

if(preg_match("/[a-z]/i", strip_tags($post_content))){

}
我做了所有的测试。如果有人按了几次enter键,然后提交,则条带标签本身就会失败。这只检查你是否至少有一个a-z,你可能希望更严格,有一个最小值,或者只允许数字,但我们不知道你在这里期望什么,所以这是一个最好的猜测

if ($("#editor").val()) {
    // textarea is not empty
   //...create query and send query to  database...
}
else{
 //do nothing
}
您还可以使用$.trim删除空白:

if ($.trim($("#editor").val())) {
    // textarea is not empty or not contains  white-space
    //...create query and send query to  database...
}
else{
   //do nothing
}

对于你的解决方案,如果(preg_match(“/[a-zA-Z]\d/i”,strip_tags($post_content)){}检查大小写,也检查数字0-9,你告诉我,这是你的问题。但是/i是不区分大小写的,所以对a-zA-Z和/i-just-pick-one的需要忽略了只返回html的问题
if ($.trim($("#editor").val())) {
    // textarea is not empty or not contains  white-space
    //...create query and send query to  database...
}
else{
   //do nothing
}