gpt4 book ai didi

javascript - JQUERY inputmask 是否可以为日期时间添加字符串?

转载 作者:行者123 更新时间:2023-11-30 15:34:33 25 4
gpt4 key购买 nike

屏蔽时间的代码(HH:mm:ss)

$('.time').each(function () { 
$(this).inputmask({
mask: "h:s:s",
placeholder: "00:00:00",
alias: "datetime",
hourFormat: "24"
});
});

如何屏蔽也接受类似 NONE 的字符串的日期时间?可以输入文本,但只有 None 值有效 NONE 或 01:00:00

我正在使用 jquery inputmask 库(https://github.com/RobinHerbots/jquery.inputmask)。

最佳答案

你不应该使用 aliasmask 因为你没有声明 alias 而只是调用 inputmask() 带有选项

这是带有注释解释的解决方案。

$('.time').inputmask({
mask:'(h:s:s)|(X)', // X will define our new validator , | mean OR
definitions: {
"X": {
// Needed since you need the word(NONE) comparaison
validator: function(chrs) {return chrs.toUpperCase().localeCompare('NONE')==0 },
cardinality: 4, // Mean 1 instance of our new validator(X) has a value of 4 chars
prevalidator: [
{validator: function(chrs){return chrs.toUpperCase().localeCompare('N')==0 },cardinality:1},
{validator: function(chrs){return chrs.toUpperCase().localeCompare('NO')==0 },cardinality:2},
{validator: function(chrs){return chrs.toUpperCase().localeCompare('NON')==0 },cardinality:3}
],
casing: "upper" // All chars will be casted as UPPER but not during our custom validation
}
}
})

里面有死亡金属:)

$('.time').inputmask({
mask:'(h:s:s)|(X)', // X will define our new validator , | mean OR
regex: Inputmask().opts.aliases.datetime.regex, //Needed for the imported validator
placeholder: "00:00:00", //To get 00:00:00 in place __:__:__
hourFormat: "24", // or 12
definitions: {
"h": Inputmask().opts.aliases.datetime.definitions.h, // first char > 2 will become 09:
"s": Inputmask().opts.aliases.datetime.definitions.s, //first char for minute/second if > 5 become 09
"X": {
// Needed since you need the word(NONE) comparaison
validator: function(chrs) {return chrs.toUpperCase().localeCompare('NONE')==0 },
cardinality: 4, // Mean 1 instance of our new validator(X) has a value of 4 chars
prevalidator: [
{validator: function(chrs){return chrs.toUpperCase().localeCompare('N')==0 },cardinality:1},
{validator: function(chrs){return chrs.toUpperCase().localeCompare('NO')==0 },cardinality:2},
{validator: function(chrs){return chrs.toUpperCase().localeCompare('NON')==0 },cardinality:3}
],
casing: "upper" // All chars will be casted as UPPER but not during our custom validation
}
}
})

关于javascript - JQUERY inputmask 是否可以为日期时间添加字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41757660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com