48 lines
984 B
TypeScript
Raw Normal View History

/**
* Toolkit - String Validation
*
* String validation utilities.
*/
/**
* Check if string is empty or only whitespace
*/
export function isEmpty(str: string | null | undefined): boolean {
return !str || str.trim().length === 0;
}
/**
* Check if string has minimum length
*/
export function hasMinLength(str: string, minLength: number): boolean {
return str.trim().length >= minLength;
}
/**
* Check if string has maximum length
*/
export function hasMaxLength(str: string, maxLength: number): boolean {
return str.trim().length <= maxLength;
}
/**
* Check if string contains only alphanumeric characters
*/
export function isAlphanumeric(str: string): boolean {
return /^[a-z0-9]+$/i.test(str);
}
/**
* Check if string contains only letters
*/
export function isAlpha(str: string): boolean {
return /^[a-z]+$/i.test(str);
}
/**
* Check if string contains only digits
*/
export function isNumeric(str: string): boolean {
return /^\d+$/.test(str);
}