UNPKG

@kitstack/nest-powertools

Version:

A comprehensive collection of NestJS powertools, decorators, and utilities to supercharge your backend development

36 lines 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidationHelper = void 0; const common_1 = require("@nestjs/common"); class ValidationHelper { static validateEmail(email) { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailRegex.test(email); } static validatePassword(password) { const errors = []; if (password.length < 8) { errors.push('Password must be at least 8 characters long'); } if (!/(?=.*[a-z])/.test(password)) { errors.push('Password must contain at least one lowercase letter'); } if (!/(?=.*[A-Z])/.test(password)) { errors.push('Password must contain at least one uppercase letter'); } if (!/(?=.*\d)/.test(password)) { errors.push('Password must contain at least one number'); } return { valid: errors.length === 0, errors, }; } static throwIfInvalid(condition, message) { if (!condition) { throw new common_1.BadRequestException(message); } } } exports.ValidationHelper = ValidationHelper; //# sourceMappingURL=validation.helper.js.map