Skip to content

Commit 38d89fb

Browse files
committed
Ajustes gerais
* Ajustado alguns validators - IsAlpha - IsAlphaNumeric - IsCEP * Adicionado novos validators - IsAscii - IsBase32 - IsBase58 - IsBoolean - IsHexColor - IsISO8601 - IsLocale - IsMagnetURI - IsMimeType - IsOctal - IsPassportNumber - IsRGBColor
1 parent 136141c commit 38d89fb

25 files changed

+808
-39
lines changed

README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,38 +257,50 @@ TDataValidator.Values
257257
|Contains |(Key) IsRequired |NormalizeEmail |
258258
|IsAlpha |(Value) CustomJSONValue |OnlyNumbers |
259259
|IsAlphaNumeric |(Value) IsArray |RemoveAccents |
260-
|IsBase64 |(Value) IsObject |Replace |
261-
|IsBetween |(Value) MinItems |ToBase64Decode |
262-
|IsBTCAddress |(Value) MaxItems |ToBase64Encode |
263-
|IsCEP |(Value) + Validação para values |ToDate |
264-
|IsCNPJ | |ToDateTime |
265-
|IsCPF | |ToHTMLDecode |
266-
|IsCPFCNPJ | |ToHTMLEncode |
267-
|IsDate | |ToInteger |
268-
|IsDateBetween | |ToLowerCase |
269-
|IsDateEquals | |ToMD5 |
270-
|IsDateGreaterThan | |ToNumeric |
271-
|IsDateLessThan | |ToTime |
272-
|IsDateTime | |ToUpperCase |
273-
|IsEmail | |ToURLDecode |
274-
|IsEmpty | |ToURLEncode |
275-
|IsEquals | |Trim |
276-
|IsEthereumAddress | |TrimLeft |
277-
|IsGreaterThan | |TrimRight |
278-
|IsHexadecimal | | |
279-
|IsInteger | | |
260+
|IsAscii |(Value) IsObject |Replace |
261+
|IsBase32 |(Value) MinItems |ToBase64Decode |
262+
|IsBase58 |(Value) MaxItems |ToBase64Encode |
263+
|IsBase64 |(Value) + Validação para values |ToDate |
264+
|IsBetween | |ToDateTime |
265+
|IsBoolean | |ToHTMLDecode |
266+
|IsBTCAddress | |ToHTMLEncode |
267+
|IsCEP | |ToInteger |
268+
|IsCNPJ | |ToLowerCase |
269+
|IsCPF | |ToMD5 |
270+
|IsCPFCNPJ | |ToNumeric |
271+
|IsDate | |ToTime |
272+
|IsDateBetween | |ToUpperCase |
273+
|IsDateEquals | |ToURLDecode |
274+
|IsDateGreaterThan | |ToURLEncode |
275+
|IsDateLessThan | |Trim |
276+
|IsDateTime | |TrimLeft |
277+
|IsEmail | |TrimRight |
278+
|IsEmpty | | |
279+
|IsEquals | | |
280+
|IsEthereumAddress | | |
281+
|IsGreaterThan | | |
282+
|IsHexadecimal | | |
283+
|IsHexColor | | |
284+
|IsInteger | | |
280285
|IsIP | | |
286+
|IsISO8601 | | |
281287
|IsJSON | | |
282288
|IsLength | | |
283289
|IsLessThan | | |
290+
|IsLocale | | |
284291
|IsLowercase | | |
285292
|IsMACAddress | | |
293+
|IsMagnetURI | | |
286294
|IsMD5 | | |
295+
|IsMimeType | | |
287296
|IsNegative | | |
288297
|IsNumeric | | |
289298
|IsOptional | | |
299+
|IsOctal | | |
300+
|IsPassportNumber | | |
290301
|IsPhoneNumber | | |
291302
|IsPositive | | |
303+
|IsRGBColor | | |
292304
|IsSSN | | |
293305
|IsTime | | |
294306
|IsTimeBetween | | |
@@ -304,4 +316,4 @@ TDataValidator.Values
304316
|IsUUIDv4 | | |
305317
|IsUUIDv5 | | |
306318
|IsZero | | |
307-
|RegexIsMatch | | |
319+
|RegexIsMatch | | |

src/core/DataValidator.Context.Intf.pas

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ interface
6161
function Contains(const AValueContains: TArray<string>; const ACaseSensitive: Boolean = False): T; overload;
6262
function IsAlpha(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
6363
function IsAlphaNumeric(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
64+
function IsAscii(): T;
65+
function IsBase32(): T;
66+
function IsBase58(): T;
6467
function IsBase64(): T;
6568
function IsBetween(const AValueA: Integer; const AValueB: Integer): T; overload;
6669
function IsBetween(const AValueA: Int64; const AValueB: Int64): T; overload;
6770
function IsBetween(const AValueA: Double; const AValueB: Double): T; overload;
6871
function IsBetween(const AValueA: Extended; const AValueB: Extended): T; overload;
6972
function IsBetween(const AValueA: Single; const AValueB: Single): T; overload;
7073
function IsBetween(const AValueA: UInt64; const AValueB: UInt64): T; overload;
74+
function IsBoolean(): T;
7175
function IsBTCAddress(): T;
7276
function IsCEP(): T;
7377
function IsCNPJ(): T;
@@ -86,19 +90,27 @@ interface
8690
function IsEthereumAddress(): T;
8791
function IsGreaterThan(const AValueGreaterThan: Integer): T;
8892
function IsHexadecimal(): T;
93+
function IsHexColor(): T;
8994
function IsInteger(): T;
9095
function IsIP(): T;
96+
function IsISO8601(): T;
9197
function IsJSON(): T;
9298
function IsLength(const AMin: Integer; const AMax: Integer): T;
9399
function IsLessThan(const AValueLessThan: Integer): T;
100+
function IsLocale(): T;
94101
function IsLowercase(): T;
95102
function IsMACAddress(): T;
103+
function IsMagnetURI(): T;
96104
function IsMD5(): T;
105+
function IsMimeType(): T;
97106
function IsNegative(): T;
98107
function IsNumeric(): T;
108+
function IsOctal(): T;
109+
function IsOptional(): T;
110+
function IsPassportNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
99111
function IsPhoneNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
100112
function IsPositive(): T;
101-
function IsOptional(): T;
113+
function IsRGBColor(): T;
102114
function IsSSN(): T;
103115
function IsTime(const AJSONISO8601ReturnUTC: Boolean = True): T;
104116
function IsTimeBetween(const AValueA: TTime; const AValueB: TTime; const AJSONISO8601ReturnUTC: Boolean = True): T;

src/core/DataValidator.Context.pas

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ TDataValidatorContext<T: IInterface> = class(TInterfacedObject, IDataValidator
3838
function Contains(const AValueContains: string; const ACaseSensitive: Boolean = False): T; overload;
3939
function IsAlpha(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
4040
function IsAlphaNumeric(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
41+
function IsAscii(): T;
42+
function IsBase32(): T;
43+
function IsBase58(): T;
4144
function IsBase64(): T;
4245
function IsBetween(const AValueA: Integer; const AValueB: Integer): T; overload;
4346
function IsBetween(const AValueA: Int64; const AValueB: Int64): T; overload;
4447
function IsBetween(const AValueA: Double; const AValueB: Double): T; overload;
4548
function IsBetween(const AValueA: Extended; const AValueB: Extended): T; overload;
4649
function IsBetween(const AValueA: Single; const AValueB: Single): T; overload;
4750
function IsBetween(const AValueA: UInt64; const AValueB: UInt64): T; overload;
51+
function IsBoolean(): T;
4852
function IsBTCAddress(): T;
4953
function IsCEP(): T;
5054
function IsCNPJ(): T;
@@ -63,19 +67,27 @@ TDataValidatorContext<T: IInterface> = class(TInterfacedObject, IDataValidator
6367
function IsEthereumAddress(): T;
6468
function IsGreaterThan(const AValueGreaterThan: Integer): T;
6569
function IsHexadecimal(): T;
70+
function IsHexColor(): T;
6671
function IsInteger(): T;
6772
function IsIP(): T;
73+
function IsISO8601(): T;
6874
function IsJSON(): T;
6975
function IsLength(const AMin: Integer; const AMax: Integer): T;
7076
function IsLessThan(const AValueLessThan: Integer): T;
77+
function IsLocale(): T;
7178
function IsLowercase(): T;
7279
function IsMACAddress(): T;
80+
function IsMagnetURI(): T;
7381
function IsMD5(): T;
82+
function IsMimeType(): T;
7483
function IsNegative(): T;
7584
function IsNumeric(): T;
85+
function IsOctal(): T;
86+
function IsOptional(): T;
87+
function IsPassportNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
7688
function IsPhoneNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage = tl_en_US): T;
7789
function IsPositive(): T;
78-
function IsOptional(): T;
90+
function IsRGBColor(): T;
7991
function IsSSN(): T;
8092
function IsTime(const AJSONISO8601ReturnUTC: Boolean = True): T;
8193
function IsTimeBetween(const AValueA: TTime; const AValueB: TTime; const AJSONISO8601ReturnUTC: Boolean = True): T;
@@ -163,8 +175,12 @@ implementation
163175
Validator.Custom,
164176
Validator.IsAlpha,
165177
Validator.IsAlphaNumeric,
178+
Validator.IsAscii,
179+
Validator.IsBase32,
180+
Validator.IsBase58,
166181
Validator.IsBase64,
167182
Validator.IsBetween,
183+
Validator.IsBoolean,
168184
Validator.IsBTCAddress,
169185
Validator.IsCEP,
170186
Validator.IsCNPJ,
@@ -183,18 +199,26 @@ implementation
183199
Validator.IsPhoneNumber,
184200
Validator.IsGreaterThan,
185201
Validator.IsHexadecimal,
202+
Validator.IsHexColor,
186203
Validator.IsInteger,
187204
Validator.IsIP,
205+
Validator.IsISO8601,
188206
Validator.IsJSON,
189207
Validator.IsLength,
190208
Validator.IsLessThan,
209+
Validator.IsLocale,
191210
Validator.IsLowercase,
192211
Validator.IsMACAddress,
212+
Validator.IsMagnetURI,
193213
Validator.IsMD5,
214+
Validator.IsMimeType,
194215
Validator.IsNegative,
195216
Validator.IsNumeric,
217+
Validator.IsOctal,
196218
Validator.IsOptional,
219+
Validator.IsPassportNumber,
197220
Validator.IsPositive,
221+
Validator.IsRGBColor,
198222
Validator.IsSSN,
199223
Validator.IsTime,
200224
Validator.IsTimeBetween,
@@ -300,6 +324,21 @@ function TDataValidatorContext<T>.IsAlphaNumeric(const ALocaleLanguage: TDataVal
300324
Result := Add(TValidatorIsAlphaNumeric.Create('Value is not alphanumeric!'), ALocaleLanguage);
301325
end;
302326

327+
function TDataValidatorContext<T>.IsAscii: T;
328+
begin
329+
Result := Add(TValidatorIsAscii.Create('Value is not ascii!'));
330+
end;
331+
332+
function TDataValidatorContext<T>.IsBase32: T;
333+
begin
334+
Result := Add(TValidatorIsBase32.Create('Value is not base32!'));
335+
end;
336+
337+
function TDataValidatorContext<T>.IsBase58: T;
338+
begin
339+
Result := Add(TValidatorIsBase58.Create('Value is not base58!'));
340+
end;
341+
303342
function TDataValidatorContext<T>.IsBase64: T;
304343
begin
305344
Result := Add(TValidatorIsBase64.Create('Value is not base64!'));
@@ -335,6 +374,11 @@ function TDataValidatorContext<T>.IsBetween(const AValueA, AValueB: UInt64): T;
335374
Result := Add(TValidatorIsBetween.Create(AValueA, AValueB, Format('Value is not between %s and %s!', [VarToStr(AValueA), VarToStr(AValueB)])));
336375
end;
337376

377+
function TDataValidatorContext<T>.IsBoolean: T;
378+
begin
379+
Result := Add(TValidatorIsBoolean.Create('Value is not boolean!'));
380+
end;
381+
338382
function TDataValidatorContext<T>.IsBTCAddress: T;
339383
begin
340384
Result := Add(TValidatorIsBTCAddress.Create('Value is not BTC (Bitcoin) Adddress!'));
@@ -432,6 +476,11 @@ function TDataValidatorContext<T>.IsHexadecimal: T;
432476
Result := Add(TValidatorIsHexadecimal.Create('Value is not hexadecimal!'));
433477
end;
434478

479+
function TDataValidatorContext<T>.IsHexColor: T;
480+
begin
481+
Result := Add(TValidatorIsHexColor.Create('Value is not HexColor!'));
482+
end;
483+
435484
function TDataValidatorContext<T>.IsInteger: T;
436485
begin
437486
Result := Add(TValidatorIsInteger.Create('Value is not integer!'));
@@ -442,6 +491,11 @@ function TDataValidatorContext<T>.IsIP: T;
442491
Result := Add(TValidatorIsIP.Create('Value is not IP (Internet Protocol)!'));
443492
end;
444493

494+
function TDataValidatorContext<T>.IsISO8601: T;
495+
begin
496+
Result := Add(TValidatorIsISO8601.Create('Value is not in the format ISO8601!'));
497+
end;
498+
445499
function TDataValidatorContext<T>.IsJSON: T;
446500
begin
447501
Result := Add(TValidatorIsJSON.Create('Value is not JSON (JavaScript Object Notation)!'));
@@ -457,6 +511,11 @@ function TDataValidatorContext<T>.IsLessThan(const AValueLessThan: Integer): T;
457511
Result := Add(TValidatorIsLessThan.Create(AValueLessThan, Format('Value is not less than %d!', [AValueLessThan])));
458512
end;
459513

514+
function TDataValidatorContext<T>.IsLocale: T;
515+
begin
516+
Result := Add(TValidatorIsLocale.Create('Value is not locale!'));
517+
end;
518+
460519
function TDataValidatorContext<T>.IsLowercase: T;
461520
begin
462521
Result := Add(TValidatorIsLowercase.Create('Value is not lowercase!'));
@@ -467,11 +526,21 @@ function TDataValidatorContext<T>.IsMACAddress: T;
467526
Result := Add(TValidatorIsMACAddress.Create('Value is not MAC (Media Access Control) address!'));
468527
end;
469528

529+
function TDataValidatorContext<T>.IsMagnetURI: T;
530+
begin
531+
Result := Add(TValidatorIsMagnetURI.Create('Value is not Magnet URI!'));
532+
end;
533+
470534
function TDataValidatorContext<T>.IsMD5: T;
471535
begin
472536
Result := Add(TValidatorIsMD5.Create('Value is not MD5!'));
473537
end;
474538

539+
function TDataValidatorContext<T>.IsMimeType: T;
540+
begin
541+
Result := Add(TValidatorIsMimeType.Create('Value is not MimeType!'));
542+
end;
543+
475544
function TDataValidatorContext<T>.IsNegative: T;
476545
begin
477546
Result := Add(TValidatorIsNegative.Create('Value is not negative!'));
@@ -482,11 +551,21 @@ function TDataValidatorContext<T>.IsNumeric: T;
482551
Result := Add(TValidatorIsNumeric.Create('Value is not numeric!'));
483552
end;
484553

554+
function TDataValidatorContext<T>.IsOctal: T;
555+
begin
556+
Result := Add(TValidatorIsOctal.Create('Value not is octal!'));
557+
end;
558+
485559
function TDataValidatorContext<T>.IsOptional: T;
486560
begin
487561
Result := Add(TValidatorIsOptional.Create('Value is optional!'));
488562
end;
489563

564+
function TDataValidatorContext<T>.IsPassportNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage): T;
565+
begin
566+
Result := Add(TValidatorIsPassportNumber.Create('Value is not passport number!'), ALocaleLanguage);
567+
end;
568+
490569
function TDataValidatorContext<T>.IsPhoneNumber(const ALocaleLanguage: TDataValidatorLocaleLanguage): T;
491570
begin
492571
Result := Add(TValidatorIsPhoneNumber.Create('Value is not phone number!'), ALocaleLanguage);
@@ -497,6 +576,11 @@ function TDataValidatorContext<T>.IsPositive: T;
497576
Result := Add(TValidatorIsPositive.Create('Value is not positive!'));
498577
end;
499578

579+
function TDataValidatorContext<T>.IsRGBColor: T;
580+
begin
581+
Result := Add(TValidatorIsRGBColor.Create('Value is not RGB Color (Red, Green, Blue)!'));
582+
end;
583+
500584
function TDataValidatorContext<T>.IsSSN: T;
501585
begin
502586
Result := Add(TValidatorIsSSN.Create('Value is not SSN (Social Security Number)!'));
@@ -574,7 +658,7 @@ function TDataValidatorContext<T>.IsZero: T;
574658

575659
function TDataValidatorContext<T>.RegexIsMatch(const ARegex: string): T;
576660
begin
577-
Result := Add(TValidatorRegexIsMatch.Create(ARegex, 'Value is not match!'));
661+
Result := Add(TValidatorRegexIsMatch.Create(ARegex, 'Value not match!'));
578662
end;
579663

580664
function TDataValidatorContext<T>.&Not: T;

src/core/DataValidator.Information.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
interface
1111

1212
uses
13-
DataValidator.Types, DataValidator.Information.Intf,
13+
DataValidator.Information.Intf,
1414
System.Classes, System.Generics.Collections, System.SysUtils;
1515

1616
type

src/core/DataValidator.JSON.Context.Intf.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
interface
1111

1212
uses
13-
DataValidator.Context.Intf, DataValidator.Types, DataValidator.Result.Intf;
13+
DataValidator.Context.Intf, DataValidator.Types;
1414

1515
type
1616
IDataValidatorJSONContextKey<T> = interface;

src/core/DataValidator.Result.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ TDataValidatorResult = class(TInterfacedObject, IDataValidatorResult)
3232
implementation
3333

3434
uses
35-
DataValidator.Information;
35+
DataValidator.Information;
3636

3737
{ TDataValidatorResult }
3838

src/core/DataValidator.Types.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
interface
1111

1212
uses
13-
DataValidator.Result.Intf,
14-
System.SysUtils, System.JSON;
13+
14+
System.JSON;
1515

1616
type
1717
TDataValidatorLocaleLanguage = (tl_en_US, tl_de_DE, tl_fr_FR, tl_it_IT, tl_es_ES, tl_ru_RU, tl_pt_BR);

src/validators/Validator.Contains.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface
1111

1212
uses
1313
DataValidator.ItemBase,
14-
System.SysUtils, System.StrUtils;
14+
System.SysUtils;
1515

1616
type
1717
TValidatorContains = class(TDataValidatorItemBase, IDataValidatorItem)

0 commit comments

Comments
 (0)