Made a better URL validator

This commit is contained in:
xemeds
2020-07-18 21:50:47 +00:00
parent d97b3266c8
commit d6721f27f7
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -14,6 +14,16 @@ def validate_URL(form, field):
# Raise a ValidationError
raise ValidationError()
# If the url starts with a dot after http:// or after https:// or just starts with a dot
if field.data.startswith("http://.") or field.data.startswith("https://.") or field.data.startswith("."):
# Raise a ValidationError
raise ValidationError()
# If the url ends with a dot and it is the only dot
if field.data.endswith(".") and field.data.count(".") == 1:
# Raise a ValidationError
raise ValidationError()
# If the URL does not start with http:// and https://
if not(field.data.startswith("http://")) and not(field.data.startswith("https://")):
# Add https:// to the beginning of the URL