Skip to Content
UtilsValidation

Validation utils

import { isEmail, isStrongPassword } from '@gg-software/utils';

All of these are format checks — they say a value looks valid, not that it exists.

isEmail

Pragmatic email check (single @, no spaces, dot in the domain).

isEmail('ada@example.com'); // true isEmail('nope@nope'); // false

isUrl

URL check via the URL constructor, restricted to the given protocols.

isUrl('https://example.com'); // true isUrl('example.com'); // false (no protocol) isUrl('javascript:alert(1)'); // false (protocol not allowed) isUrl('ftp://files.example.com', ['ftp:']); // true
ParameterTypeDefault
valuestring
protocolsstring[]['http:', 'https:']

isPhone

Permissive international check: optional leading +, digits with spaces / dashes / dots / parentheses, 7–15 digits total (E.164 bounds).

isPhone('+420 601 123 456'); // true isPhone('601123456'); // true isPhone('12ab34'); // false

isStrongPassword

Strength check against configurable requirements.

isStrongPassword('Passw0rd'); // true (default rules) isStrongPassword('passw0rd'); // false (no uppercase) isStrongPassword('Sup3r$ecret', { symbol: true }); // true

Defaults (PasswordRequirements):

OptionDefaultMeaning
minLength8minimum length
uppercasetrueat least one A–Z
lowercasetrueat least one a–z
numbertrueat least one digit
symbolfalseat least one non-alphanumeric