1

我正在使用 asp.net 形式的 jQuery 验证引擎。如何使用正则表达式验证字段(必需) ?

http://www.position-relative.net/creation/formValidator/

jQuery(document).ready(function () {
    // binds form submission and fields to the validation engine
    jQuery("#aspnetForm").validationEngine('attach', {
        'custom_error_messages': {
            // Custom Error Messages for Validation Types
            '.reqSomeField': {
                'required': {
                    'message': "Please enter Some Field."
                }
            }
        }
    });
});
4

1 回答 1

0

到目前为止,您尝试过什么?

但这里有一些可以帮助您入门的东西。它来自文档

custom[regex_name] 将元素的值验证为预定义的正则表达式列表。

因此,首先您需要在 jquery-validation-engine.js 文件中创建自定义正则表达式,然后在表单字段中调用它。表单字段中的语法如下所示:

<input value="someone@nowhere.com" class="validate[required,custom[email]]" type="text" name="email" id="email" />

您是否尝试过简单地将此类添加到表单字段中?

<input value="" class="validate[required]" type="text" name="email" id="email" />

除了强制用户在字段中输入 SOMETHING 之外,这不会进行任何验证。但是,他们可以在字段中输入 $$$,并且表单会认为这是有效的。如果您正在执行内联验证,特别是使用此插件,您可能希望使用现有的电子邮件地址验证选项,包含字母和数字但没有标点符号的内容,仅数字字段等。预先存在的选项都列在文档中。

于 2012-12-02T22:58:23.623 回答