开发者

regular expression for 'must be loger than {n} and must include at least 2 digit integer'

Can anyone give me an example of a regular expression for must be loger than {n} and must include at least 2 digit integer

I have the following for now but it only validates the length;

<asp:RegularExpressionValidator ID="myTxtVal" 
    runat="server" ControlToValidate="myTxt" 
    ErrorMessage="Input Is Too Short" Valida开发者_如何学编程tionExpression=".{15}.*" />


<asp:RegularExpressionValidator ID="myTxtVal"
  runat="server" ControlToValidate="myTxt"      
  ErrorMessage="Input Is Too Short" ValidationExpression="^(?=.*?\d{2}).{15}" />

Edit: fixed for 2 digit integer. Not the same as 'has 2 digits'... ;-) It uses the lookahead to validate that there are at least two digits in a row, then the .{15} part to match 15 characters. It doesn't need to match the rest of the string, so I removed the .*.


Something like that?

^(?=.*\d{2}).{4,}$

See it here at Regexr

The first construct (?=.*\d{2}) is a look ahead, it checks if somewhere in your string are 2 digits in a row. (I am not sure at this point if it is what you need)

The second part checks .{4,} checks the length of the string for at least 4 characters.

^ anchors the pattern to the start of the string

$ anchors the pattern to the end of the string


Just another method, purely for your interest:

/^(.|()\d\d){N-1}\2/

This works in flavours of regex where back referencing with \N fails to match if the Nth group to which it refers failed to match. The expression can only successfully match if the second group was matched, which in turn can only happen if \d\d matches. For example, N = 15:

/^(.|()\d\d){14}\2/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜