简体   繁体   English

如何验证p,li,div元素文本

[英]how to validate p,li,div elements text

I want to validate the p,li,div element texts. 我想验证p,li,div元素文本。 examples, I have an p tag with the class name "date". 例如,我有一个带有类名称“ date”的p标记。 then the user can insert only a date.if they inserting text I want to display alert to the user in CKEDITOR . 那么用户只能插入一个日期。如果他们在CKEDITOR中插入我要向用户显示警报的文本。

Is it possible to in ckeditor without using any input fields <p class="date"></p> 是否可以在ckeditor中不使用任何输入字段<p class="date"></p>

<p class="date">31/07/2018</p>

<p class="date">a</p> I need to display error or alert. <p class="date">a</p>我需要显示错误或警报。

how can i do without onchange events. 没有onchange事件怎么办。 is there have any default funtionality 是否有任何默认功能

You can get elements by class in jQuery. 您可以在jQuery中按类获取元素。 Then the validation process is straightforward 然后验证过程很简单

function isDate(value) {
    var dateReg = /^\d{2}([./-])\d{2}\1\d{4}$/
    return value.match(dateReg)
}

$("p.date").map(function() {
    if(!isDate(this.innerHTML)) {
        //alert("...");
    }
});

As for the part - when to run these validation checks, you can call them on DOM updates like, insertion, deletion etc in the application layer. 至于部分-何时运行这些验证检查,则可以在应用程序层中的DOM更新(例如插入,删除等)上调用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM