Made a better URL validator
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user