Limit number of alpha characters in regular expression

Posted by beardedd on Stack Overflow See other posts from Stack Overflow or by beardedd
Published on 2010-06-09T14:56:40Z Indexed on 2010/06/09 15:02 UTC
Read the original article Hit count: 203

Filed under:

I've been struggling to figure out how to best do this regular expression.

Here are my requirements:

  • Up to 8 characters
  • Can only be alphanumeric
  • Can only contain up to three alpha characters [a-z] (zero alpha characters are valid to)

Any ideas would be appreciated.

This is what I've got so far, but it only looks for contiguous letter characters:

^(\d|([A-Za-z])(?!([A-Za-z]{3,}))){0,8}$

© Stack Overflow or respective owner

Related posts about regex