What is the right regular expression to validate FQDN in C# and Javascript? I have been searching all around and I find different specifications. Which one is correct.
Few Examples I found :
1.(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)
2. (?=^.{1,254}$)(^(?:(?!\d|-)[a-zA-Z0-9\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)
3. \b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b
(Regular Expression cook book)
Please help
Generally, the Regular Expressions cookbook is a good source of information, written by two regex experts, so you should be starting there. The solution outlined there is not quite adapted to your needs yet (it doesn't validate an entire string but matches substrings, and it doesn't check for the overall length of the string), so we can modify it a little:
Explanation: