Oh, I thought you needed only 4 total chars.

Using a regex probably is a bit overkill here:

>>> import string
>>> accepted = string.letters + string.digits
>>> max_numbers = 4
>>>
>>> def test(word):
...     numbers = 0
...     for c in word:
...         if c.isdigit():
...             numbers += 1
...         if not c in accepted or numbers > max_numbers:
...             return False
...     return True
...
>>>
>>> test('gerd12')
True
>>> test('gerd1234')
True
>>> test('gerd 1234 ')
False
>>> test('gerd 1234')
False
>>> test('%$$%%#$')
False
>>> test('gerd123456')
False



On Sat, Aug 31, 2013 at 6:11 PM, Gerd Koetje <[email protected]>wrote:

> to explain myself a bit more:
>
> gerd12 = should be valid
> gerd1234   = should be valid
> gerd 1234 = should not be valid
> %$$%%#$ = should not be valid
> gerd123456 - should not be valid
>
> etc etc
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to