1

Tabulator JS 与 python 烧瓶。

columns:[
{title:"Number", field:"msisdn", align:"center", editable:true,  editor:"input", validator:["required","numeric","min:11","max:11","regex:\\77[0-9]+"]},

],

我想在启用单元格编辑模式时验证单元格。通过格式 77XXXXXXXXX 限制数字,但这个正则表达式匹配不起作用,我在 jquery 函数中使用模拟匹配,工作得很好。

请帮忙。

4

3 回答 3

0

我解决我的问题。添加自定义格式化程序:

var numEditor = function(cell, onRendered, success, cancel, editorParams){
    var editor = document.createElement("input");
    editor.setAttribute("type", "text");
    var r = /^77[0-9]{9}$/
    onRendered(function(){
             editor.focus();
             editor.style.css = "100%";
    });
    function successFunc(){
        var n = editor.value.match(r);
                if (n !== null) {
                    success(editor.value);
                }
                else {
                   cancel();
                }
    }
    editor.addEventListener("change", successFunc);
    editor.addEventListener("blur", successFunc);
    return editor;
};

在制表符中:

{title:"", field:"msisdn", align:"center", editable:true, editor:numEditor},

玩得开心))

谢谢奥利,你的 Tabulator JS 着火了!

于 2019-01-16T00:27:02.460 回答
0

您的正则表达式在那里看起来不对,应该是77[0-9]{9}

所以你的列定义应该是:

{title:"Number", field:"msisdn", align:"center", editable:true,  editor:"input", validator:["required","numeric","min:11","max:11","regex:77[0-9]{9}"]},

我希望这会有所帮助,

干杯

奥利:)

于 2018-10-06T15:24:09.003 回答
0
{title:"Number", field:"msisdn", align:"center", editable:true,  editor:"input", validator:["required","numeric","min:11","max:11","regex:77[0-9]{9}"]},

仅通过处理正则表达式时不能像在制表器中那样工作RegExp("string"),它需要RegExp("string", "gi")确保处理所有正则表达式。

于 2020-05-04T18:39:55.027 回答