0

我使用了这个正则表达式 ^(?=. [a-zA-Z]. )[a-zA-Z0-9 ?.! @#'\s]{2,200}$。它应该包含特殊的 (! @#) 字母数字字符,并且最多允许 200 个字符。但是在这里我得到了像未终止的字符串常量这样的错误..在谷歌我试过......它是说我们需要用 \ 替换像 $,* 这样的元字符我做不到..任何人都可以帮助我

我的代码是这样的

$.validationEngineLanguage = {
    newLang: function(){
        $.validationEngineLanguage.allRules = {
            "required": { // Add your regex rules here, you can take telephone as an   example
                "regex": "none",
                "alertText": "This field is required",
                "alertTextCheckboxMultiple": "* Please select an option",
                "alertTextCheckboxe": "* This checkbox is required",
                "alertTextDateRange": "* Both date range fields are required"
            },
            ---
             ----
            "passwordval": {
            "regex":^(?=.*[a-zA-Z].*)[a-zA-Z0-9 ?.!*@#'\s]{2,200}$,
            "alertText": "* Not a valid password"
            },
            };

    }
};

$.validationEngineLanguage.newLang();

我在“passwordval”中遇到问题:

4

2 回答 2

0
var reExample = new RegExp("^(?=.[a-zA-Z].)[a-zA-Z0-9 ?.!@#'\s]{2,200}$");

注意“”

reExample.test("dfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdfdfsfsdfsdf");

以上产生错误

reExample.test("dfsfsdfsdfdfsfsd");

这产生了真

(假设您使用的是 javascript)

于 2012-04-10T12:58:02.490 回答
0

您的正则表达式中似乎有错误

  • 更改此行

    "regex" : ^(?=.*[a-zA-Z].*)[a-zA-Z0-9 ?.!*@#'\s]{2,200}$,
    

    "regex" : "^(?=.*[a-zA-Z].*)[a-zA-Z0-9 ?.!*@#'\\s]{2,200}$",
    

注意

The double quote around the regular expression and the extra \ before \s 
于 2012-04-10T13:08:54.083 回答