Skip to content

Commit

Permalink
Merge pull request #23 from PandaTechAM/development
Browse files Browse the repository at this point in the history
validator changes and nuget updates
  • Loading branch information
HaikAsatryan authored Dec 20, 2024
2 parents 8699463 + e9e961a commit 8e08ff9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ The package includes extension methods to simplify common validation scenarios:
- String Validations:
- IsValidJson(): Validates that a string is a valid JSON.
- IsXssSanitized(): Validates that a string is sanitized against XSS attacks.
- IsEmail(): Validates that a string is a valid email address. Native one is not working correctly.
- IsPhoneNumber(): Validates that a string is a valid phone number. Format requires area code to be in `()`.
- IsEmailOrPhoneNumber(): Validates that a string is either a valid email address or a valid phone number.

## Cors

Expand Down
8 changes: 4 additions & 4 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.22</Version>
<Version>1.0.23</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
Expand All @@ -27,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.12.3" />
<PackageReference Include="FluentDateTime" Version="3.0.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
Expand All @@ -52,7 +52,7 @@
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.3" />
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.3" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.63" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.66" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
using FluentValidation;
using Microsoft.AspNetCore.Http;
using RegexBox;

namespace SharedKernel.ValidatorAndMediatR.Validators;

public static class ValidatorExtensions
{
public static IRuleBuilderOptions<T, string?> IsEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
{
return ruleBuilder.Must(x => x is null || PandaValidator.IsEmail(x))
.WithMessage("email_format_is_not_valid");
}

public static IRuleBuilderOptions<T, string?> IsPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
{
return ruleBuilder.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x))
.WithMessage("phone_number_format_is_not_valid");
}

public static IRuleBuilderOptions<T, string?> IsEmailOrPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
{
return ruleBuilder
.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x) || PandaValidator.IsEmail(x))
.WithMessage("phone_number_or_email_format_is_not_valid");
}

public static IRuleBuilderOptions<T, string?> IsPhoneNumberOrEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
{
return ruleBuilder.IsEmailOrPhoneNumber();
}

public static IRuleBuilderOptions<T, IFormFile?> HasMaxFileSize<T>(this IRuleBuilder<T, IFormFile?> ruleBuilder,
int maxFileSizeInMb)
{
Expand Down

0 comments on commit 8e08ff9

Please sign in to comment.