29

I need regex for asp.net application to match an alphanumeric string at least 6 characters long.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
onder
  • 795
  • 3
  • 14
  • 32

3 Answers3

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
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