It passes because the "llll" part of the string fullfils the criteria - the "#####" part is ignored. Try it - Add
MessageBox.Show("Matched: " + regex.Match(name));
and you will see what I mean.
You could try:
Regex regex = new Regex("^[a-zA-Z0-9_\\.-]{1,20}");
if (!regex.IsMatch(name))
{
return true;
}
which forces the match to be at the beginning of the string.
It may be worth your while to get a copy of
Expresso - it examines and generates Regular expressions - and its free!