English 中文(简体)
否认特殊性质 j Query Validate
原标题:denying special characters jQuery Validate

我需要验证一个文本,使用Plugin j Query Validate,以便我使用一个格列车,我添加一个图形方法:

$.validator.addMethod(
    "regex",
    function(value, element, regexp) {
        var check = false;
        var re = new RegExp(regexp);
        return this.optional(element) || re.test(value);
    },
    "No special Characters allowed here. Use only upper and lowercase letters (A through Z; a through z), numbers and punctuation marks (. , : ; ?     " - = ~ ! @ # $ % ^ & * ( ) _ + / < > { } )"
);

然后,在备选办法中,我补充说:

comments:{
    required: true,
    maxlength: 8000,
    regex: /[^A-Za-zd-=~!@#\%&*()_+\/<>?{}.$‘^+" ;:,s]/
}

这种“工作”以某种方式发现无效特性并显示电文,只有在特殊性质是盒子中唯一的特性时,问题才是有效的。

| `` ° ¬ // This shows the error message but...
test | // This won t show the message

因此,如果允许属性,则验证工作就停止了。 我失踪了吗?

P.S. I m 确实,这与原始原因I ve测试了reg鱼,它很好地发挥作用。

最佳回答

检验只具有有效特性的检验标准,而不是测试特殊性的存在。

regex: /^[A-Za-zd=#$%...-]+$/

将<代码>......改为你希望允许的所有特殊性质。 如上所示,<代码>#、$%-。 注:您不必在<代码>[内逃避(多数)性质。

如果你允许<条码>-,它必须是否则试图穿透范围的最后特性。 (例如,[a-c]对a, b, c.[a-c-]对a, b, c和-)

另外,如果你允许<条码><>>>>>,则不能成为第一种特性,以其他方式加以规范,作为<条码>而不是的操作者(例如<条码>[^bc]与非、b或c的任何特性相匹配)。


在您的上述例子中,完全的监管者可能会发现这样的情况。

regex: /^[A-Za-zs`~!@#$%^&*()+={}|;: ",.<>/?\-]+$/

Explanation

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  [A-Za-                   any character of:  A  to  Z ,  a  to  z ,
  zs`~!@#$%^&*()+={}|     whitespace (
, 
, 	, f, and " "),  ` ,
  ;: ",.<>/?\-]+           ~ ,  ! ,  @ ,  # ,  $ ,  % ,  ^ ,  & ,
                            * ,  ( ,  ) ,  + ,  = ,  { ,  } ,  | ,
                            ; ,  : ,    ,  " ,  , ,  . ,  < ,  > ,
                            / ,  ? ,  \ ,  -  (1 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  $                        before an optional 
, and the end of the
                           string

“check

问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...