@@ -23,11 +23,26 @@ https://jitpack.io/#multiform-validator/java/
23
23
- isCreditCardValid
24
24
- identifyCreditCard
25
25
26
+ - FileValidator
27
+ - isValidAudio
28
+ - file (File) - required
29
+ - audioExtensions (String[ ] ) - default: [ "mp3", "wav"]
30
+ - You can exclude the extensions you don't want to validate
31
+ - isValidImage
32
+ - file (File) - required
33
+ - imageExtensions (String[ ] ) - default: [ "ico", "jpeg", "png", "gif"]
34
+ - You can exclude the extensions you don't want to validate
35
+ - isValidPdf
36
+ - file (File) - required
37
+ - pdfExtensions (String) - default: "pdf"
38
+ - isValidTxt
39
+ - file (File) - required
40
+ - txtExtensions (String) - default: "txt"
26
41
- Utils
27
42
- getOnlyEmail
28
43
- getOnlyEmailWithOptions (options)
29
44
- multiple (boolean) - default: false
30
- - cleanDomain (boolean) - default: false
45
+ - cleanDomain (boolean | Arrays< String > ) - default: false
31
46
- repeatEmail (boolean) - default: false
32
47
33
48
- Validate
@@ -109,6 +124,34 @@ public class Main {
109
124
}
110
125
```
111
126
127
+ ### FileValidator
128
+
129
+ ``` java
130
+ import io.github.multiform_validator.FileValidator ;
131
+
132
+ import java.io.File ;
133
+
134
+ public class Main {
135
+ public static void main (String [] args ) {
136
+ File file = new File (" path/to/file" );
137
+ System . out. println(FileValidator . isValidAudio(file)); // true | false
138
+ System . out. println(FileValidator . isValidImage(file)); // true | false
139
+ System . out. println(FileValidator . isValidPdf(file)); // true | false
140
+ System . out. println(FileValidator . isValidTxt(file)); // true | false
141
+
142
+ exampleExcludingExtensions();
143
+ }
144
+
145
+ public static void exampleExcludingExtensions () {
146
+ File file = new File (" path/to/file" );
147
+ String [] audioExtensions = {" mp3" };
148
+ String [] imageExtensions = {" ico" , " jpeg" , " png" };
149
+ System . out. println(FileValidator . isValidAudio(file, audioExtensions)); // true | false
150
+ System . out. println(FileValidator . isValidImage(file, imageExtensions)); // false | true
151
+ }
152
+ }
153
+ ```
154
+
112
155
### Utils
113
156
114
157
``` java
@@ -117,12 +160,12 @@ import io.github.multiform_validator.Utils;
117
160
public class Main {
118
161
public static void main (String [] args ) {
119
162
String msg1
= " This is a message example with [email protected] email to test" ;
120
- System . out
. println(
Utils . getOnlyEmail(msg1));
// [email protected]
163
+ System . out
. println(
Utils . getOnlyEmail(msg1
, null ));
// [email protected]
121
164
122
165
String msg2
= " Example two [email protected] and [email protected] " ;
123
166
// With options
124
167
Utils . GetOnlyEmailOptionsParams options = new Utils .GetOnlyEmailOptionsParams ();
125
- options. multiple = true ;
168
+ options. setMultiple( true ) ;
126
169
System . out
. println(
Utils . getOnlyEmailWithOptions(msg2, options));
// [[email protected] , [email protected] ]
127
170
}
128
171
}
@@ -134,6 +177,8 @@ public class Main {
134
177
import io.github.multiform_validator.Validate ;
135
178
import io.github.multiform_validator.Validate.ValidateEmailOptionsParams ;
136
179
180
+ import java.util.Collections ;
181
+
137
182
public class Main {
138
183
public static void main (String [] args ) {
139
184
validateEmailExample();
@@ -148,27 +193,27 @@ public class Main {
148
193
149
194
// Email validation with options: maxLength
150
195
ValidateEmailOptionsParams optionsMaxLength = new ValidateEmailOptionsParams ();
151
- optionsMaxLength. maxLength = 10 ; // Setting max length to 10, which should fail for longer emails
196
+ optionsMaxLength. setMaxLength( 10 ) ; // Setting max length to 10, which should fail for longer emails
152
197
boolean isValidMaxLength
= Validate . validateEmail(
" [email protected] " , optionsMaxLength);
153
198
System . out. println(" Is valid with maxLength: " + isValidMaxLength); // Expected: false
154
199
155
200
// Email validation with options: country specific
156
201
ValidateEmailOptionsParams optionsCountry = new ValidateEmailOptionsParams ();
157
- optionsCountry. country = " us" ; // Expecting an email from the US
202
+ optionsCountry. setCountry( " us" ) ; // Expecting an email from the US
158
203
boolean isNotValidCountry
= Validate . validateEmail(
" [email protected] " , optionsCountry);
159
204
boolean isValidCountry
= Validate . validateEmail(
" [email protected] " , optionsCountry);
160
205
System . out. println(" Is not valid with country: " + isNotValidCountry); // Expected: false
161
206
System . out. println(" Is valid with country: " + isValidCountry); // Expected: true
162
207
163
208
// Email validation with options: validDomains
164
209
ValidateEmailOptionsParams optionsValidDomains = new ValidateEmailOptionsParams ();
165
- optionsValidDomains. validDomains = true ; // Only allow certain domains (implementation specific)
210
+ optionsValidDomains. setValidDomains( true ) ; // Only allow certain domains (implementation specific)
166
211
boolean isValidValidDomains
= Validate . validateEmail(
" [email protected] " , optionsValidDomains);
167
212
System . out. println(" Is valid with validDomains: " + isValidValidDomains); // Expected: true
168
213
169
214
// Email validation with options: validDomainsList
170
215
ValidateEmailOptionsParams optionsValidDomainsList = new ValidateEmailOptionsParams ();
171
- optionsValidDomainsList. validDomainsList . add (" specificdomain.com" ); // Adding a specific domain to the list
216
+ optionsValidDomainsList. setValidDomainsList( Collections . singletonList (" specificdomain.com" ) ); // Adding a specific domain to the list
172
217
boolean isValidValidDomainsList
= Validate . validateEmail(
" [email protected] " , optionsValidDomainsList);
173
218
System . out. println(" Is valid with validDomainsList: " + isValidValidDomainsList); // Expected: true
174
219
}
0 commit comments