TypeScript utility enforcing password complexity (length, uppercase, lowercase, digit) with i18n-ready error keys for client and server.
// Source: https://github.com/im4codes/imcodes | License: MIT | Copyright 2026 IM.codes
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Shared password complexity rules — used by both server and web.
*
* Requirements:
* - At least 8 characters
* - At least one uppercase letter
* - At least one lowercase letter
* - At least one digit
*/
export interface PasswordValidationResult {
valid: boolean;
/** Error key for i18n (e.g. 'password_too_short', 'password_missing_uppercase') */
errorKey: string | null;
}
export function validatePasswordComplexity(password: string): PasswordValidationResult {
if (password.length < 8) {
return { valid: false, errorKey: 'password_too_short' };
}
if (!/[A-Z]/.test(password)) {
return { valid: false, e
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key