2025-10-03 14:26:55 +09:00
|
|
|
/**
|
|
|
|
|
* Toolkit - String Validation
|
2025-12-25 17:30:02 +09:00
|
|
|
*
|
2025-10-03 14:26:55 +09:00
|
|
|
* 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);
|
|
|
|
|
}
|