@@ -473,18 +473,50 @@ handler. If validation fails, a `BadRequestException` is thrown with the validat
473473
474474### FluentValidation Extensions
475475
476- The package includes extension methods to simplify common validation scenarios:
477-
478- - File Validations:
479- - HasMaxFileSize(maxFileSizeInMb): Validates that an uploaded file does not exceed the specified maximum size.
480- - FileTypeIsOneOf(allowedFileExtensions): Validates that the uploaded file has one of the allowed file
481- extensions.
482- - String Validations:
483- - IsValidJson(): Validates that a string is a valid JSON.
484- - IsXssSanitized(): Validates that a string is sanitized against XSS attacks.
485- - IsEmail(): Validates that a string is a valid email address. Native one is not working correctly.
486- - IsPhoneNumber(): Validates that a string is a valid phone number. Format requires area code to be in ` () ` .
487- - IsEmailOrPhoneNumber(): Validates that a string is either a valid email address or a valid phone number.
476+ We ship lightweight validators and presets for common scenarios, including file uploads and string checks.
477+ All file rules use name/extension checks only (simple + fast). Deep validation still happens inside your storage layer.
478+
479+ ** File upload validators**
480+
481+ ** Single file (` IFormFile ` )**
482+
483+ ``` csharp
484+ RuleFor (x => x .Avatar )
485+ .HasMaxSizeMb (6 ) // size cap in MB
486+ .ExtensionIn (" .jpg" , " .jpeg" , " .png" ); // or use a preset set below
487+
488+ ```
489+
490+ ** File collection (` IFormFileCollection ` )**
491+
492+ ``` csharp
493+ RuleFor (x => x .Docs )
494+ .MaxCount (10 ) // number of files
495+ .EachHasMaxSizeMb (10 ) // per-file size cap (MB)
496+ .EachExtensionIn (CommonFileSets .Documents )
497+ .TotalSizeMaxMb (50 ); // sum of all files (MB)
498+ ```
499+
500+ ** Presets**
501+
502+ ``` csharp
503+ using SharedKernel .ValidatorAndMediatR .Validators .Files ;
504+
505+ CommonFileSets .Images // .jpg, .jpeg, .png, .webp, .heic, .heif, .svg, .avif
506+ CommonFileSets .Documents // .pdf, .txt, .csv, .json, .xml, .yaml, .yml, .md, .docx, .xlsx, .pptx, .odt, .ods, .odp
507+ CommonFileSets .ImagesAndAnimations // Images + .gif
508+ CommonFileSets .ImagesAndDocuments // Images + Documents
509+ ```
510+
511+ ** String validators**
512+
513+ ``` csharp
514+ RuleFor (x => x .Email ).IsEmail ();
515+ RuleFor (x => x .Phone ).IsPhoneNumber ();
516+ RuleFor (x => x .Contact ).IsEmailOrPhoneNumber (); // alias: IsPhoneNumberOrEmail
517+ RuleFor (x => x .PayloadJson ).IsValidJson ();
518+ RuleFor (x => x .Content ).IsXssSanitized ();
519+ ```
488520
489521## Cors
490522
0 commit comments