[Answer]-Django – Filter URL in texts

1👍

You can do something like:

simple_url_re = re.compile(r'^(https?)?://\[?\w', re.IGNORECASE)
simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE)

if simple_url_re.match(text) or simple_url_2_re.match(text):
    raise ValidationError

you can use django’s urlize for ideas

Leave a comment