views:

58

answers:

3

Hi,

I need regex for asp.net application.

regex for only alphanumeric, but at least 6 character.

Thanks

+2  A: 

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
Note though that this does not match the letter 'ö', amongst others.
Fredrik Mörk
@Fredrik Mörk: I guess that is obvious.
Gumbo
@Gumbo: I 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
+2  A: 

^\w{6,}$ ^[a-zA-Z0-9]{6,}$

(Depending on the Regex implementation)

Note, that \w also matches _!

ApoY2k
`a-Z` is not a valid character range.
Gumbo
OOps :D My mistake
ApoY2k
+3  A: 

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
Nice, didn't knew that!
ApoY2k