valia
Version:
A runtime data validator in TypeScript with advanced type inference, built-in validation functions, and seamless integration for server and client environments.
22 lines (18 loc) • 542 B
text/typescript
/*
Composition :
letter = %d65-%d90 / %d97-%d122; A-Z / a-z
digit = %x30-39; 0-9
label = letter [*(digit / letter / "-") digit / letter]
domain = label *("." label)
Links :
https://datatracker.ietf.org/doc/html/rfc1035#section-2.3.1
*/
const domainRegex = new RegExp("^[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?)*$");
/**
* **Standard :** RFC 1035
*
* @version 1.0.0
*/
export function isDomain(str: string, params?: undefined): boolean {
return (domainRegex.test(str));
}