我需要在wysihtml5启用的textarea元素上添加验证,仅作为输入使用空格。
当我只在textarea中输入空格时,控制台具有以下值:
<br>
我的验证规则无效:
if (!$.trim(<textarea value>)) {
// textarea is empty or contains only white-space
toastr.error("You forgot to write your answer body, kindly write some thing in answer box.");
return false;
}
我没有获得任何wysihtml5选项来验证输入值,这只是空格
$('#some-textarea').wysihtml5({
"font-styles": true, //Font styling, e.g. h1, h2, etc. Default true
"emphasis": true, //Italics, bold, etc. Default true
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
"html": false, //Button which allows you to edit the generated HTML. Default false
"link": true, //Button to insert a link. Default true
"image": true, //Button to insert an image. Default true,
"color": false //Button to change color of font
});
答案 0 :(得分:0)
我设法按如下方式完成:
var name = $("#textAreaInput").val(); # <br>
var n = name.replace(/ /g,'');
var c = n.replace(/^( )+/g, '');
var f = c.replace(/^(<br>)+/g, '');
if (f.length==0) {
toastr.error("Display error");
return false;
}
谢谢
答案 1 :(得分:0)
对于未来的此类要求,建议您获取编辑器的值:
var name = $("#textAreaInput").data('wysihtml5').editor.getValue();
var validateWysi = name.replace(/ /g,'').replace(/^( )+/g, '').replace(/^(<br>)+/g, '').replace(/^(<br\/>)+/g, '');
if(validateWysi.length==0)
{
toastr.error("Display error");
return false;
}