Skip to content

Commit 8e08ff9

Browse files
authored
Merge pull request #23 from PandaTechAM/development
validator changes and nuget updates
2 parents 8699463 + e9e961a commit 8e08ff9

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ The package includes extension methods to simplify common validation scenarios:
404404
- String Validations:
405405
- IsValidJson(): Validates that a string is a valid JSON.
406406
- IsXssSanitized(): Validates that a string is sanitized against XSS attacks.
407+
- IsEmail(): Validates that a string is a valid email address. Native one is not working correctly.
408+
- IsPhoneNumber(): Validates that a string is a valid phone number. Format requires area code to be in `()`.
409+
- IsEmailOrPhoneNumber(): Validates that a string is either a valid email address or a valid phone number.
407410

408411
## Cors
409412

src/SharedKernel/SharedKernel.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.0.22</Version>
11+
<Version>1.0.23</Version>
1212
<PackageId>Pandatech.SharedKernel</PackageId>
1313
<Title>Pandatech Shared Kernel Library</Title>
1414
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
@@ -27,8 +27,8 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="8.0.1" />
31-
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
30+
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="9.0.0" />
31+
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
3232
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.12.3" />
3333
<PackageReference Include="FluentDateTime" Version="3.0.0" />
3434
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
@@ -52,7 +52,7 @@
5252
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.3" />
5353
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
5454
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.3" />
55-
<PackageReference Include="Scalar.AspNetCore" Version="1.2.63" />
55+
<PackageReference Include="Scalar.AspNetCore" Version="1.2.66" />
5656
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
5757
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
5858
</ItemGroup>

src/SharedKernel/ValidatorAndMediatR/Validators/ValidatorExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
using FluentValidation;
22
using Microsoft.AspNetCore.Http;
3+
using RegexBox;
34

45
namespace SharedKernel.ValidatorAndMediatR.Validators;
56

67
public static class ValidatorExtensions
78
{
9+
public static IRuleBuilderOptions<T, string?> IsEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
10+
{
11+
return ruleBuilder.Must(x => x is null || PandaValidator.IsEmail(x))
12+
.WithMessage("email_format_is_not_valid");
13+
}
14+
15+
public static IRuleBuilderOptions<T, string?> IsPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
16+
{
17+
return ruleBuilder.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x))
18+
.WithMessage("phone_number_format_is_not_valid");
19+
}
20+
21+
public static IRuleBuilderOptions<T, string?> IsEmailOrPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
22+
{
23+
return ruleBuilder
24+
.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x) || PandaValidator.IsEmail(x))
25+
.WithMessage("phone_number_or_email_format_is_not_valid");
26+
}
27+
28+
public static IRuleBuilderOptions<T, string?> IsPhoneNumberOrEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
29+
{
30+
return ruleBuilder.IsEmailOrPhoneNumber();
31+
}
32+
833
public static IRuleBuilderOptions<T, IFormFile?> HasMaxFileSize<T>(this IRuleBuilder<T, IFormFile?> ruleBuilder,
934
int maxFileSizeInMb)
1035
{

0 commit comments

Comments
 (0)