jQuery匹配模式 [英] jQuery matching pattern

查看:144
本文介绍了jQuery匹配模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to validate my inputs with jQuery before a form is sent.

这是我的输入字段在数据库中插入无值

This is what my input fields look like when there is no value inserted in the database:

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

这是我的输入字段看起来像有现有值插入数据库:

This is what my input fields look like when there is an existing value inserted in the database:

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






我想:


I would like to:


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

  • Check if the value is already in the database

用户想要将
现有值替换为零或零和
禁止它。

Check if the user want to replace an existing value by nothing or zero and disallow it.

检查用户是否尝试
在新字段中插入0,
不允许。

Check if the user is trying to insert 0 in a new field and disallow it.

已解决:

Solved:

  $("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^='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;
                    }
                });

这篇关于jQuery匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆