c# - Regex to validate length of alphanumeric string -
i have following regular expression: ^[a-za-z0-9]+( [a-za-z0-9]+)*$ i'm trying validate string between 0-10 characters, string cannot contain more 2 spaces in row or cannot empty. string cannot contain special characters , can case insensitive , can include hyphens. how can limit input between 0-10 characters? i tried ^[a-za-z0-9]+( [a-za-z0-9]+{0,10})*$ but not work. i this: ^(?!.* )(?=.*[\w-])[\w -]{1,10}$ this uses negative look-ahead (?!.* ) assert there not 2 consecutive spaces, , positive look-ahead (?=.*[\w-]) assert has @ least 1 non-space character (i assume "empty" means "only spaces"). note if can't "empty", can't 0 length, length range must 1-10, not 0-10. of tiny note fact don't need escape dash in character class if it's first or last character.