Skip to content

Commit

Permalink
chore: update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Jul 13, 2024
1 parent 94d0142 commit f61e88f
Show file tree
Hide file tree
Showing 21 changed files with 393 additions and 234 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
12 changes: 11 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
12 changes: 11 additions & 1 deletion .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

258 changes: 33 additions & 225 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,52 @@

## JAVA >=8

## Source code

- [Multiform-Validator](https://github.com/Multiform-Validator/java/)

## How to install

follow the steps below to use the library in your project.

https://jitpack.io/#multiform-validator/java/
- [jitpack.io](https://jitpack.io/#Multiform-Validator/java) - Add the repository in your pom.xml

```xml

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

```xml

<dependency>
<groupId>com.github.multiform-validator</groupId>
<artifactId>java</artifactId>
<version>0.0.4</version>
</dependency>
```

## Available methods - JAVA (0.0.4)v

- CnpjValidator
- cnpjIsValid
- [CnpjValidator](https://multiform-validator.github.io/java/classes/CnpjValidator)

- [CpfValidator](https://multiform-validator.github.io/java/classes/CpfValidator)

- CpfValidator
- cpfIsValid
- [CreditCardValidator](https://multiform-validator.github.io/java/classes/CreditCardValidator)

- CreditCardValidator
- isCreditCardValid
- identifyCreditCard
- [FileValidator](https://multiform-validator.github.io/java/classes/FileValidator)

- FileValidator
- isValidAudio
- file (File) - required
- audioExtensions (String[]) - default: ["mp3", "wav"]
- You can exclude the extensions you don't want to validate
- isValidImage
- file (File) - required
- imageExtensions (String[]) - default: ["ico", "jpeg", "png", "gif"]
- You can exclude the extensions you don't want to validate
- isValidPdf
- file (File) - required
- pdfExtensions (String) - default: "pdf"
- isValidTxt
- file (File) - required
- txtExtensions (String) - default: "txt"
- Utils
- getOnlyEmail
- getOnlyEmailWithOptions (options)
- multiple (boolean) - default: false
- cleanDomain (boolean | Arrays<String>) - default: false
- repeatEmail (boolean) - default: false
- [Utils](https://multiform-validator.github.io/java/classes/Utils)

- Validate
- validateEmail
- maxLength (int) - default: 400
- country (String) - default: ""
- validDomains (boolean) - default: false
- validDomainsList (String[]) - default: ["@gmail.com",
"@outlook.com",
"@yahoo.com",
"@icloud.com",
"@hotmail.com",
"@mail.ru",
"@yandex.ru",
"@gmx.com",
"@zoho.com",
"@protonmail.com",
"@protonmail.ch"]
- [Validate](https://multiform-validator.github.io/java/classes/Validate)

- Validator
- isAscii
- isCEP
- isDate
- isDecimal
- isEmail
- isMACAddress
- isNumber
- isPort
- isPostalCode
- isTime
- [Validator](https://multiform-validator.github.io/java/classes/Validator)

## How to use
## Example how to use

### CnpjValidator

Expand All @@ -92,171 +68,3 @@ public class Main {
}
}
```

### CpfValidator

```java
// You can also import the method as static or use the full path

import static io.github.multiform_validator.CpfValidator.cpfIsValid;

public class Main {
public static void main(String[] args) {
String cpfTrue = "123.456.789-09";
String cpfFalse = "123.456.789-10";
System.out.println(cpfIsValid(cpfTrue)); // true
System.out.println(cpfIsValid(cpfFalse)); // false
}
}
```

### CreditCardValidator

```java
import io.github.multiform_validator.CreditCardValidator;

public class Main {
public static void main(String[] args) {
String creditCard = "4532 8770 0040 4166";
System.out.println(CreditCardValidator.isCreditCardValid(creditCard)); // true
System.out.println(CreditCardValidator.identifyCreditCard(creditCard)); // Visa
}
}
```

### FileValidator

```java
import io.github.multiform_validator.FileValidator;

import java.io.File;

public class Main {
public static void main(String[] args) {
File file = new File("path/to/file");
System.out.println(FileValidator.isValidAudio(file)); // true | false
System.out.println(FileValidator.isValidImage(file)); // true | false
System.out.println(FileValidator.isValidPdf(file)); // true | false
System.out.println(FileValidator.isValidTxt(file)); // true | false

exampleExcludingExtensions();
}

public static void exampleExcludingExtensions() {
File file = new File("path/to/file");
String[] audioExtensions = {"mp3"};
String[] imageExtensions = {"ico", "jpeg", "png"};
System.out.println(FileValidator.isValidAudio(file, audioExtensions)); // true | false
System.out.println(FileValidator.isValidImage(file, imageExtensions)); // false | true
}
}
```

### Utils

```java
import io.github.multiform_validator.Utils;

public class Main {
public static void main(String[] args) {
String msg1 = "This is a message example with foo@bar.com email to test";
System.out.println(Utils.getOnlyEmail(msg1, null)); // foo@bar.com

String msg2 = "Example two foo1@bar.com and foo2@bar.com";
// With options
Utils.GetOnlyEmailOptionsParams options = new Utils.GetOnlyEmailOptionsParams();
options.setMultiple(true);
System.out.println(Utils.getOnlyEmailWithOptions(msg2, options)); // [foo1@bar.com, foo2@bar.com]
}
}
```

### Validate

```java
import io.github.multiform_validator.Validate;
import io.github.multiform_validator.Validate.ValidateEmailOptionsParams;

import java.util.Collections;

public class Main {
public static void main(String[] args) {
validateEmailExample();
}

public static void validateEmailExample() {
// IMPORTANT: validDomains can not be used with validDomainsList, you can use only one of them

// Basic email validation
boolean isValid = Validate.validateEmail("example@example.com");
System.out.println("Is valid: " + isValid); // Expected: true

// Email validation with options: maxLength
ValidateEmailOptionsParams optionsMaxLength = new ValidateEmailOptionsParams();
optionsMaxLength.setMaxLength(10); // Setting max length to 10, which should fail for longer emails
boolean isValidMaxLength = Validate.validateEmail("longemail@example.com", optionsMaxLength);
System.out.println("Is valid with maxLength: " + isValidMaxLength); // Expected: false

// Email validation with options: country specific
ValidateEmailOptionsParams optionsCountry = new ValidateEmailOptionsParams();
optionsCountry.setCountry("us"); // Expecting an email from the US
boolean isNotValidCountry = Validate.validateEmail("example@domain.com", optionsCountry);
boolean isValidCountry = Validate.validateEmail("example@domain.com.us", optionsCountry);
System.out.println("Is not valid with country: " + isNotValidCountry); // Expected: false
System.out.println("Is valid with country: " + isValidCountry); // Expected: true

// Email validation with options: validDomains
ValidateEmailOptionsParams optionsValidDomains = new ValidateEmailOptionsParams();
optionsValidDomains.setValidDomains(true); // Only allow certain domains (implementation specific)
boolean isValidValidDomains = Validate.validateEmail("example@gmail.com", optionsValidDomains);
System.out.println("Is valid with validDomains: " + isValidValidDomains); // Expected: true

// Email validation with options: validDomainsList
ValidateEmailOptionsParams optionsValidDomainsList = new ValidateEmailOptionsParams();
optionsValidDomainsList.setValidDomainsList(Collections.singletonList("specificdomain.com")); // Adding a specific domain to the list
boolean isValidValidDomainsList = Validate.validateEmail("example@specificdomain.com", optionsValidDomainsList);
System.out.println("Is valid with validDomainsList: " + isValidValidDomainsList); // Expected: true
}
}
```

### Validator

```java
import io.github.multiform_validator.Validator;

public class Main {
public static void main(String[] args) {
validMethods();
invalidMethods();
}

public void validMethods() {
System.out.println(Validator.isAscii("foo")); // true
System.out.println(Validator.isCEP("12345-678")); // true
System.out.println(Validator.isDate("2021-01-01")); // true
System.out.println(Validator.isDecimal("1.5")); // true
System.out.println(Validator.isMACAddress("00:00:00:00:00:00")); // true
System.out.println(Validator.isNumber("123")); // true
System.out.println(Validator.isPort("8080")); // true
System.out.println(Validator.isPostalCode("12345-678")); // true
System.out.println(Validator.isTime("12:00")); // true
System.out.println(Validator.isEmail("foo@bar.com")); // true
}

public void invalidMethods() {
System.out.println(Validator.isAscii("こんにちは")); // false
System.out.println(Validator.isCEP("12345678")); // false
System.out.println(Validator.isDate("2021-01-32")); // false
System.out.println(Validator.isDecimal("1.5.5")); // false
System.out.println(Validator.isMACAddress("00:00:00:00:00:00:00")); // false
System.out.println(Validator.isNumber("123a")); // false
System.out.println(Validator.isPort("8080a")); // false
System.out.println(Validator.isPostalCode("12345678")); // false
System.out.println(Validator.isTime("12:00:00")); // false
System.out.println(Validator.isEmail("foo@bar")); // false
}
}
```

Lib is in development, there's other validators that you can use, but they are not yet documented.
13 changes: 12 additions & 1 deletion docs/classes/CnpjValidator.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ public class Main {
System.out.println(CnpjValidator.cnpjIsValid(cnpjFalse)); // false
}
}
```
```

## Other classes validation methods

- [CpfValidator](https://multiform-validator.github.io/java/classes/CpfValidator)
- [CreditCardValidator](https://multiform-validator.github.io/java/classes/CreditCardValidator)
- [FileValidator](https://multiform-validator.github.io/java/classes/FileValidator)
- [Utils](https://multiform-validator.github.io/java/classes/Utils)
- [Validate](https://multiform-validator.github.io/java/classes/Validate)
- [Validator](https://multiform-validator.github.io/java/classes/Validator)

## Return to [Home](https://multiform-validator.github.io/java/)
13 changes: 9 additions & 4 deletions docs/classes/CpfValidator.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CpfValidator

The `CpfValidator` class is used to validate CPF numbers. It has a single method, `cpfIsValid`, which receives a `String` as a parameter and returns a `boolean` value.
The `CpfValidator` class is used to validate CPF numbers. It has a single method, `cpfIsValid`, which receives
a `String` as a parameter and returns a `boolean` value.

## How to use

Expand All @@ -19,9 +20,13 @@ public class Main {
}
```

## Other methods
## Other classes validation methods

- [CnpjValidator](https://multiform-validator.github.io/java/classes/CnpjValidator)
- [CreditCardValidator](https://multiform-validator.github.io/java/classes/CreditCardValidator)
- [FileValidator](https://multiform-validator.github.io/java/classes/FileValidator)
- [Utils](https://multiform-validator.github.io/java/classes/Utils)
- [Validate](https://multiform-validator.github.io/java/classes/Validate)
- [Validator](https://multiform-validator.github.io/java/classes/Validator)

## Return to [Home](https://multiform-validator.github.io/java/)
[]: # (end)
## Return to [Home](https://multiform-validator.github.io/java/)
Loading

0 comments on commit f61e88f

Please sign in to comment.