first validation

This commit is contained in:
2024-05-17 16:46:17 -05:00
parent 782c254a33
commit 747435bfba
7 changed files with 70 additions and 19 deletions

View File

@@ -165,3 +165,42 @@ export interface ImageProperty {
code: string;
name: string;
}
export interface ErrorResponse {
fields?: FieldError[];
general?: string[];
}
export interface FieldError {
fieldname: string;
message: string;
}
export function isEmpty(value: any): boolean {
// Check for undefined or null
if (value === undefined || value === null) {
return true;
}
// Check for empty string or string with only whitespace
if (typeof value === 'string') {
return value.trim().length === 0;
}
// Check for number and NaN
if (typeof value === 'number') {
return isNaN(value);
}
// If it's not a string or number, it's not considered empty by this function
return false;
}
export function emailToDirName(email: string): string {
// Entferne ungültige Zeichen und ersetze sie durch Unterstriche
const sanitizedEmail = email.replace(/[^a-zA-Z0-9_-]/g, '_');
// Entferne führende und nachfolgende Unterstriche
const trimmedEmail = sanitizedEmail.replace(/^_+|_+$/g, '');
// Ersetze mehrfache aufeinanderfolgende Unterstriche durch einen einzelnen Unterstrich
const normalizedEmail = trimmedEmail.replace(/_+/g, '_');
return normalizedEmail;
}