Regex Match for Domain Name in Django Model
django, model, python, regex
Solution
To recap the clarifications above: You want to match only domains with a single alphanumeric label and a TLD of up to 4 characters, eg. "domain.com" or "someotherdomain.info" or "345xyz.pdq1" but not "subdomain.domain.com", "http://domain.com", "www.domain.com", or "345xyz.abcde". This regex will do it:
^[a-z0-9]+\.[a-z0-9]{1,4}$
Problem
I have one table, which looks like: ``` class Tld(models.Model): domainNm = models.CharField(validators=[ RegexValidator('^[0-9]^[a-z]','yourdomain.com only','Invalid Entry')], max_length=40) dtCreated = models.DateField() ``` for domainNm - I want to validate on any entry that looks like: - domain.com - 1domain.com - domain1.com It has to follow this way : `<domainname>.[com|biz|net]` etc and be alphanumeric. How do I do this on the model level of a django model? Thanks