原創(chuàng)|使用教程|編輯:龔雪|2021-08-25 09:56:07.707|閱讀 287 次
概述:Kendo UI 的Spreadsheet控件的驗證類型不直接基于RegExp規(guī)則,本文主要介紹如何創(chuàng)建基于RegExp的自定義驗證。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spreadsheet的驗證類型不直接基于RegExp的規(guī)則。
要解決此問題,請使用允許您傳遞任何公式的自定義驗證類型。 當公式返回非假值時,驗證將通過。 雖然內(nèi)置函數(shù)不包括 RegExp 匹配函數(shù),但自定義函數(shù)很容易創(chuàng)建。
<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組件庫,可快速構(gòu)建出色的高性能響應(yīng)式Web應(yīng)用程序。Kendo UI for jQuery提供在短時間內(nèi)構(gòu)建現(xiàn)在Web應(yīng)用程序所需要的一切,從多個UI組件中選擇,并輕松地將它們組合起來,創(chuàng)建出酷炫響應(yīng)式的應(yīng)用程序,同時將開發(fā)時間加快了50%。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)