Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#721 closed defect (fixed)

isAlphaNumericURL validator should allow dashes.

Reported by: Esaj Owned by: Adrian Holovaty
Component: Validators Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


django.core.validators.isAlphaNumericURL should allow dashes. Dashes in URLs are apparently more search-engine friendly, and they don't do any harm.

Index: django/core/
--- django/core/   (revision 1066)
+++ django/core/   (working copy)
@@ -13,7 +13,7 @@
 _datere = r'\d{4}-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[12][0-9])|(?:3[0-1]))'
 _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?'
 alnum_re = re.compile(r'^\w+$')
-alnumurl_re = re.compile(r'^[\w/]+$')
+alnumurl_re = re.compile(r'^[-\w/]+$')
 ansi_date_re = re.compile('^%s$' % _datere)
 ansi_time_re = re.compile('^%s$' % _timere)
 ansi_datetime_re = re.compile('^%s %s$' % (_datere, _timere))
@@ -58,7 +58,7 @@

 def isAlphaNumericURL(field_data, all_data):
     if not
-        raise ValidationError, "This value must contain only letters, numbers, underscores or slashes."
+        raise ValidationError, "This value must contain only letters, numbers, underscores, dashes or slashes."

 def isSlug(field_data, all_data):
     if not

Attachments (1)

alnumurl.diff (1.0 KB) - added by Esaj 12 years ago.

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by Esaj

Attachment: alnumurl.diff added

comment:1 Changed 12 years ago by Adrian Holovaty

Resolution: wontfix
Status: newclosed

A hyphen isn't an alphanumeric character, so it shouldn't be allowed in the isAlphaNumericURL validator. Feel free to write your own validator that takes care of hyphens.

comment:2 Changed 12 years ago by Esaj

Resolution: wontfix
Status: closedreopened

It's true that it's not an alphanumeric character, but I think it's worth allowing hyphens in URLs for flatfiles. That's actually the only reason I opened this ticket, but I forgot to say it... oops!

comment:3 Changed 12 years ago by Adrian Holovaty

Resolution: fixed
Status: reopenedclosed

(In [2353]) Fixed #721 -- isAlphaNumericURL validator now allows dashes

Note: See TracTickets for help on using tickets.
Back to Top