原創|使用教程|編輯:龔雪|2021-08-25 09:56:07.707|閱讀 287 次
概述:Kendo UI 的Spreadsheet控件的驗證類型不直接基于RegExp規則,本文主要介紹如何創建基于RegExp的自定義驗證。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spreadsheet的驗證類型不直接基于RegExp的規則。
要解決此問題,請使用允許您傳遞任何公式的自定義驗證類型。 當公式返回非假值時,驗證將通過。 雖然內置函數不包括 RegExp 匹配函數,但自定義函數很容易創建。
<script> // Define a REGEXP_MATCH function that returns true if a string // matches a given pattern (regexp). kendo.spreadsheet.defineFunction("REGEXP_MATCH", function(str, pattern, flags){ var rx; try { rx = flags ? new RegExp(pattern, flags) : new RegExp(pattern); } catch(ex) { // could not compile regexp, return some error code return new kendo.spreadsheet.CalcError("REGEXP"); } return rx.test(str); }).args([ [ "str", "string" ], [ "pattern", "string" ], [ "flags", [ "or", "string", "null" ] ] ]); </script> <div id="spreadsheet"></div> <script> var spreadsheet = $("#spreadsheet").kendoSpreadsheet({ columnWidth: 100 }).getKendoSpreadsheet(); var sheet = spreadsheet.activeSheet(); sheet.range("A1").value("IP Address in B1:"); // Using custom validation, you can pass any formula and the cell // validates if the formula returns a non-false value (see the `from` field). sheet.range("B1").validation({ comparerType: "custom", dataType: "custom", from: 'REGEXP_MATCH(B1, "^[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}$")' }); // Note the difficulty of properly quoting a regexp in a string. // An alternative would be to write the regexp in a // variable and encode it with JSON.stringify, i.e.: // // var rx = "^[0-9]{1,3}\\.[0-9]{1,3}\\." etc // // and then pass it like this // // from: '=REGEXP_MATCH(B1, ' + JSON.stringify(rx) + ')' </script>
Kendo UI for jQuery是完整的jQuery UI組件庫,可快速構建出色的高性能響應式Web應用程序。Kendo UI for jQuery提供在短時間內構建現在Web應用程序所需要的一切,從多個UI組件中選擇,并輕松地將它們組合起來,創建出酷炫響應式的應用程序,同時將開發時間加快了50%。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網