RegEx - JavaScript - Validate a known domain with any protocol, subdomains and folders -
RegEx - JavaScript - Validate a known domain with any protocol, subdomains and folders -
i need validate known domain, domain.com javascript, need validate subdomain or sub-subdomains , so, , protocol , folder, sub-folder, , so, have regular expression:
regex: /http:\/\/([\.|a-z]+).domain([\.|a-z]+)\//
the problem not gets https/ftp/ftps... , domain.com/domain.org... need validate, this:
to validate: *://*.domain.com/* example: http://example.domain.com/subfolder2/folder24/ example: https://subdomain.domain.com/folder/ example: ftp://www.example.domain.com/folder2/folder/ example: http://www.domain.com/folder/sub-folder/
i mean, protocol, subdomain, , folder, , of course, of them too:
example: https://example.domain.com/folder/folder/
any idea?
try regex:
/^(https?|ftp):\/\/[.a-z]+\.domain\.com[.a-z0-9/-]+/
this match domains lisited:
class="lang-none prettyprint-override">http://example.domain.com/subfolder2/folder24/ https://subdomain.domain.com/folder/ ftp://www.example.domain.com/folder2/folder/ http://www.domain.com/folder/sub-folder/
how works:
# / - regex start, # ^ - match start of string, # (https?|ftp) - followed `https`, `http` or `ftp`, # :\/\/ - followed `://`, # [.a-z]+ - followed amount of letters or periods, # \. - followed period, # domain\.com - followed domain name, # [.a-z0-9/-]+ - followed rest of possible url. # / - regex end.
javascript regex
Comments
Post a Comment