@@ -23,28 +23,22 @@ def validate_username(username):
2323 errs .append (ValidationError (
2424 _ ('Username must be at least 3 characters long.' ),
2525 code = 'username_min_length' ))
26- if re .search (r'[^\w. -]' , username ):
26+ if re .search (r'[^\w_ -]' , username ):
2727 errs .append (ValidationError (
28- _ ('Username must only include numbers, letters, and underscores .' ),
28+ _ ('Username must only include numbers, letters, underscores and dashes .' ),
2929 code = 'username_charset' ))
30- if re .search (r'\W ' , username [0 ]):
30+ if re .search (r'[^\w_] ' , username [0 ]):
3131 errs .append (ValidationError (
32- _ ('Username must begin with a number, letter or underscore.' ),
32+ _ ('Username must begin with a letter, number or underscore.' ),
3333 code = 'username_initial_charset' ))
34- if re .search (r'[^A-Za-z0-9 ]' , username [- 1 ]):
34+ if re .search (r'[^\w_ ]' , username [- 1 ]):
3535 errs .append (ValidationError (
36- _ ('Username must end with a letter or number .' ),
36+ _ ('Username must end with a letter, number or underscore .' ),
3737 code = 'username_ending_charset' ))
38- if re .search (r'[-_. ]{2,}' , username ):
38+ if re .search (r'[-_]{2,}' , username ):
3939 errs .append (ValidationError (
4040 _ ('Username must not contain two special characters in a row.' ),
4141 code = 'username_double_special' ))
42- if re .search (
43- r'\.(js|json|css|htm|html|xml|jpg|jpeg|png|gif|bmp|ico|tif|tiff|woff)$' ,
44- username ):
45- errs .append (ValidationError (
46- _ ('Username must not end with a confusing file suffix.' ),
47- code = 'username_file_suffix' ))
4842 if errs :
4943 raise ValidationError (errs )
5044
0 commit comments