diff options
author | Matthew Miller <matthew@millerti.me> | 2022-03-04 08:58:58 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-03-04 08:58:58 -0800 |
commit | c277856acfcaa101e275ac7262010819ec85bf95 (patch) | |
tree | 3316dc06472e1bbba63c2f30218089daab4b3f3d /packages/browser/src/helpers/isValidDomain.ts | |
parent | 4a8fb255d4fd6fbc146dedf0a2efc938b99f5973 (diff) |
Add registration error identifier logic
Diffstat (limited to 'packages/browser/src/helpers/isValidDomain.ts')
-rw-r--r-- | packages/browser/src/helpers/isValidDomain.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/isValidDomain.ts b/packages/browser/src/helpers/isValidDomain.ts new file mode 100644 index 0000000..ee68818 --- /dev/null +++ b/packages/browser/src/helpers/isValidDomain.ts @@ -0,0 +1,11 @@ +/** + * A simple test to determine if a hostname is a properly-formatted domain name + * + * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain + * + * Regex sourced from here: + * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html + */ +export function isValidDomain(hostname: string): boolean { + return /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname); +} |