Reputation: 585
What regex would allows text or numbers, or text and number (with no spaces) and a maximum length of 255 characters?
Upvotes: 0
Views: 1450
Reputation: 336418
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}$
Upvotes: 2
Reputation: 11556
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
Upvotes: 5