[英]Detect markup symbols inside textarea
I have a textarea on the page. 我在页面上有一个文本区域。 And decide validate this element.
并决定验证此元素。 I insert simple text and in js I check the length this element.
我插入简单的文本,并在js中检查此元素的长度。 But when I delete all text I can save without any problem.
但是,当我删除所有文本时,可以毫无问题地保存。 I see in firebug and in textarea I find
我在萤火虫和textarea中看到了
<ul></ul><br/>
} }
// js // js
for(var i=0; length > i; i++){
value = textElements[i].value;
if(value == "" ||(value == "<br/>" && element.tagName == "TEXTAREA")){
full = false;
emptyElements.push(elements[i]);
} else {
empty = false;
elements[i].style.borderColor = "";
elements[i].style.border = "";
}
}
Ad HTML 广告HTML
<br /><div id="edit-contentFrame-form:editor" style="visibility:hidden"><textarea id="edit-contentFrame-form:editor_input" name="edit-contentFrame-form:editor_input"><h3></h3><h3></h3><h3><br/></h3><ul>
</ul></textarea></div>
I try to find existing way to resolve this problem. 我尝试找到解决此问题的现有方法。 But nothing to find.
但是什么也找不到。
///EDITED
function isEmptyTextArea(){
var str = document.getElementById('edit-contentFrame-form:editor_input').value;
var regexp = new RegExp("(<+[\w]+>+)*", "g");
var matches_array_tags = str.replace(regexp, '');
if(matches_array_tags.length == 0){
return true;
}
return false;
}
如果您不希望人们能够输入html,则可以使用正则表达式来替换文本区域中的所有“标记符号”标签,并将其剥离。
var txtarea = document.getElementById('txtarea');
if(escape(txtarea.value) === '')
// textarea is empty
Not including whitespaces: 不包括空格:
if(escape(txtarea.value.trim()) === '')
// textarea is empty (not including whitespaces)
I resolve my problem with next js function 我用下一个js函数解决了我的问题
function isCompleteTagContent(str){
var re= /<\S[^><]*>/g;
var matches_array_tags = str.replace(re, "");
if(matches_array_tags.trim().length == 0){
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.