I am working on a DNS panel in PHP and I have to validate a DNS record name without the trailing dot. Here are a few examples:
example.com - match
sub.example.com - match
sub.sub.example.com - match
*.example.com - match
*.sub.example.com - match
sub.*.example.com - no mach
sub*.example.com - no match
*sub.example.com - no match
I am currently using this regex but the problem is it won't match a wildcard (*):
^(?!\-)(?:[a-z\d\-]{0,62}[a-z\d]\.){1,126}(?!\d+)[a-z\d]{1,63}$
I am not so good in formating regex. What is the best way to achieve this? Thanks!