开发者

Javascript Regular Expression and square brackets

I have a string that I need to get a number from.

this is my string:

alphanumeric|minlength[2]|maxlength[7]

I need to get the minlength number. (I don't always know what the minlength number will be)

How can I do this with a javascript regular expression?

Here's my full javascript 开发者_如何学JAVAcode:

var attributes = e.attr('data-validate');
var pattern = /minlength\[(\d+)\]\/;
var params = attributes.match(pattern);
console.log(params);


The following should match what you want. And, it will capture the number in brackets that you want.

/minlength\[([^\]]+)\]/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜