i want to make regex for checking that full FQDN of domain
But i tried pattern like this and not working, its return all to true
I got this pattern from ChatGPT btw
Code:
const isValidFqdn = (fqdn) => {
const fqdnRegex = /^(?=.{1,253}$)(?!:\/\/)(?!-)[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/,
return fqdnRegex.test(fqdn);
};
Results that i want:
console.log(isValidFqdn('example.com')); // false
console.log(isValidFqdn('example.com.ph')); // false
console.log(isValidFqdn('www.example.com')); // true
console.log(isValidFqdn('www.example.com.ph')); // true
console.log(isValidFqdn('www-images.example.com')); // true
console.log(isValidFqdn('www.example-testing.com')); // true