ReactQuill:验证空输入值(显示html标签)

问题描述 投票:2回答:1

我在验证ReactQuill时遇到问题。

场景:当我删除ReactQuill Textarea中的输入时,最后一个值将是

<p><br></p>

问题:如何验证最后一个值是否为<p><br></p>,我试图获取值并对其进行验证。但该值仍在插入而没有数据。我不知道我的代码或ReactQuill中的问题出在哪里

Sample Image

状态:

 const datas = {
    textValue: this.state.text
 }

我的状况:

 if(datas.textValue.length === 0 || datas.textValue.value == '<p><br></p>')
 {
    return 'false';
 }
 else
 {
    return 'true';
 }
reactjs
1个回答
1
投票

React Quill使用HTML标记进行标记。要按用户检查输入文本的长度,我们可以使用以下正则表达式过滤掉datas.textValue中的html标签,并修剪空白(如果存在)。

if(datas.textValue.replace(/<(.|\n)*?>/g, '').trim().length === 0) {
    //textarea is still empty
}
© www.soinside.com 2019 - 2024. All rights reserved.