AABBbaby

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

Kendo UI for jQuery入门级教程:Spreadsheet - 创建基于RegExp的自定义验证

Kendo UI for jQuery最新版工具下载

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 | 下载试用

Kendo UI for jQuery是完整的jQuery UI组件库,可快速构建出色的高性能响应式Web应用程序。Kendo UI for jQuery提供在短时间内构建现在Web应用程序所需要的一切,从多个UI组件中选择,并轻松地将它们组合起来,创建出酷炫响应式的应用程序,同时将开发时间加快了50%。


了解最新Kendo UI最新资讯,请关注Telerik中文网!

posted on   AABBbaby  阅读(72)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-08-26 DevExpress WPF v20.1:全新升级Map、Pivot Grid控件功能
2019-08-26 Kendo UI for jQuery使用教程:小部件DOM元素结构
点击右上角即可分享
微信分享提示