ts-validation-lite
v2.0.20
Published
Lightweight, type-safe validation utility library for web developers
Maintainers
Readme
ts-validation-lite
Lightweight, type-safe validation utility library for web developers.
Installation
npm install ts-validation-liteUsage
import { Injectable } from '@angular/core';
import { ValidationUtils } from 'ts-validation-lite';
@Injectable({ providedIn: 'root' })
export class MyService {
constructor(private val: ValidationUtils) { }
myMethod(): void {
this.val.isEmail('[email protected]'); // true
this.val.isStrongPassword('Test123!'); // {valid: true, score: 4}
}
}Methods
| Method | Description | Example |
|--------|-------------|---------|
| isEmail | Validate email format | '[email protected]' → true |
| isUrl | Validate URL format | 'https://google.com' → true |
| isPhone | Validate phone number | '+1234567890' → true |
| isPostalCode | Validate US postal code | '12345' → true |
| isStrongPassword | Check password complexity | 'Test123!' → {valid: true, score: 4} |
| isNumeric | Check if string is only numbers | '123' → true |
| isAlpha | Check if string is only letters | 'abc' → true |
| isAlphanumeric| Check if string is letters/numbers | 'abc123' → true |
| isDate | Check if string is valid date | '2024-01-01' → true |
| isJSON | Check if string is valid JSON | '{"a":1}' → true |
| isCreditCard | Validate credit card (Luhn) | '4111...' → true |
License
MIT
