I need regex for asp.net application to match an alphanumeric string at least 6 characters long.
Asked
Active
Viewed 8.3k times
29
-
1Just for the record: What do you mean by alphanumeric? Only the latin characters `a`–`z`, `A`–`Z`, and the digits `0`–`9`? – Gumbo Sep 07 '10 at 12:09
-
yes, sometimes with some turkish letters like ĞÜŞİÖÇçöişüğ. – onder Sep 07 '10 at 13:11
-
I thing its changing for country to country. – onder Sep 07 '10 at 13:12
-
1In that case use the Unicode character property character classes. – Gumbo Sep 09 '10 at 06:06
3 Answers
56
I’m not familiar with ASP.NET. But the regular expression should look like this:
^[a-zA-Z0-9]{6,}$
^
and $
denote the begin and end of the string respectively; [a-zA-Z0-9]
describes one single alphanumeric character and {6,}
allows six or more repetitions.

Gumbo
- 643,351
- 109
- 780
- 844
-
2Note though that this does not match the letter 'ö', amongst others. – Fredrik Mörk Sep 07 '10 at 11:59
-
1
-
1I am confident you were aware of this (especially since you are living in a country where this is an issue, judging from your profile), but I have come across plenty of people that are not; that's why I commented on it. – Fredrik Mörk Sep 07 '10 at 12:11
-
1
-
How to modify this regex to accommodate at-least one character and at-least one digit with a total length of 11 – Zaveed Abbasi Jun 13 '17 at 15:09
16
I would use this:
^[\p{L}\p{N}]{6,}$
This matches Unicode letters (\p{L}
) and numbers (\p{N}
), so it's not limited to common letters the Latin alphabet.

Fredrik Mörk
- 155,851
- 29
- 291
- 343
7
^\w{6,}$
^[a-zA-Z0-9]{6,}$
(Depending on the Regex implementation)
Note, that \w
also matches _
!

F.P
- 17,421
- 34
- 123
- 189