I am using python and would like a simple regex to check for a domain name's validity. I check at least write domain name.
url = 'https://stackoverflow'
keyword = 'foo'
with self.assertRaises(ValueError):
check_keyword(url, keyword)
I try unit testing on url textfield and there is main.py page where I done the validation main.py-
def check_keyword(url, keyword):
if re.match("^(((([A-Za-z0-9]+){1,63}\.)|(([A-Za-z0-9]+(\-)+[A-Za-z0-9]+){1,63}\.))+){1,255}$" ,url):
return ValueError("Invalid")
Example
www.google (Invalid)
https://stackoverflow (Invalid)
If you want to find out if a domain name is validated, simply type the URL into the WHOIS database. The search results will also provide you with other crucial information such as who owns it, when it was registered and when it is due to expire.
[A-Za-z0-9-]{1, 63} represents the domain name should be a-z or A-Z or 0-9 and hyphen (-) between 1 and 63 characters long. (? <!
php function is_valid_domain_name($domain_name) { return (preg_match("/^([a-z\d](-*[a-z\d])*)(\. ([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check && preg_match("/^. {1,253}$/", $domain_name) //overall length check && preg_match("/^[^\.]{ 1,63}(\.
The source of the validators module shows, that this is maybe a little more complex task.
You could use that module:
>>> import validators
>>> validators.domain('example.com')
True
>>> validators.domain('example.com/')
ValidationFailure(func=domain, ...)
Or you can use the RFCs for Domain names to construct your own checker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With