Regular expression for alphanumeric (Unicode) with specific length

Valid entries must contain at least one number or letter (6 to 15 characters long) in any order. ex

11111a

111a11

a11111

      

I found similar posts on SO, but they don't seem to be okay ...

+2


source to share


4 answers


This will match 6 to 15 characters (letters or numbers) except for all numbers or all letters:

^(\p{L}|\p{N}){6,15}(?<=\p{L}.*)(?<=\p{N}.*)$

      

aaaaa1aaaa matches



1111111a11 matches

aaaaaaaaaa does not match

1111111111 does not match

+3


source


You will need a query ahead for this.

You can create a regexp token that will try to find a match, but will not "consume" the input string. You can keep track of it with a simple 2nd query that will check the length of your string.

You can combine them to create your desired query.

The syntax for the .Net version of the regexp engine would be something like this:



This regex is only recorded in this chat and is not validated ... so spare :)

I'm not sure what "symbol or letter" means, but I'm assuming you mean "aZ"

(? =. * [A-Za-Z]). {6.15}

0


source


It looks like it works:

^(?=.*[a-zA-Z].*)\w{6,15}(?<=.*\d.*)$

      

And here it is with test cases:

http://regexhero.net/tester/?id=83761a1e-f6ae-4660-a91f-9cdc4d69c7b3

Basically, my idea was to first use a positive outlook to include at least one letter. Then I use \ w {5,16} as a simple means of ensuring that I match the correct number of characters (and that they are alphanumeric). And then at the end, I use a positive lookbehind to ensure that the string contains at least one number.

0


source


which should do this: \ w {6,15} if you want to match a whole string: ^ \ w {6,15} $

-1


source







All Articles