开发者

How to write regex to enforce maximum of 255 characters, with no spaces?

What regex would allows text or num开发者_如何学运维bers, or text and number (with no spaces) and a maximum length of 255 characters?


You want something like:

^[a-zA-Z0-9]{,255}$

^ matches the beginning of the string [a-zA-Z0-9] matches an alpha numeric character {,255} means up to 255 of the previous part (alpha numeric character) $ matches the end of the string


If your regex flavor knows Unicode, you can use

^[\p{L}\p{N}]{0,255}$

You can also use

^\w{0,255}$

although that will miss non-ASCII letters in some regex flavors, and it will also allow the underscore _. If you don't want that, try

^[^\W_]{0,255}$
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜