gpt4 book ai didi

jQuery 匹配模式

转载 作者:行者123 更新时间:2023-12-01 07:35:45 25 4
gpt4 key购买 nike

我正在尝试在发送表单之前使用 jQuery 验证我的输入。

这就是当数据库中插入没有值时我的输入字段的样子:

    <input
class="field"
type="text"
style="background-color: rgb(255, 255, 255);"
value="" name="input_18748_388_1257894000_"/>

当数据库中插入现有值时,我的输入字段如下所示:

    <input
class="field"
type="text"
style="background-color: rgb(255, 255, 255);"
value=""
name="input_18748_388_1257894000_46549876"/>
<小时/>

我愿意:

  • 检查该值是否已在数据库中

  • 检查用户是否想要更换现有值(value)为零或为零,并且禁止它。

  • 检查用户是否尝试在新字段中插入 0 并禁止它。

<小时/>

已解决:

  $("input[name^='input_"+var+"_']")
.each(function() {
if ($(this).attr('name').match(/^input_\d+_\d+_\d+_\d+/)
&& ($(this).val() == '' || $(this).val() <= 0))
{
displayDialog("<?=_('error')?>")
flag_error = 1;
return false;
}
});
// Submit the form.

最佳答案

试试这个:

$('input[name]')
.filter (function () {
return $(this).attr('name').match (/^input_\d+_\d+_\d+_.+/$);
})
.each (function () {
if ($(this).val() <= 0) {
//... raise a fuss ...
}
});

这需要根据您的喜好在提交更改时调用。

关于jQuery 匹配模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1920838/

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