Skip to content

Commit

Permalink
chore: update README with usage doc
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Jul 11, 2024
1 parent a7d767f commit 90a1215
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 40 deletions.
23 changes: 1 addition & 22 deletions .idea/workspace.xml

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

146 changes: 128 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,145 @@ follow the steps below to use the library in your project.

https://jitpack.io/#multiform-validator/java/

## Example of how to use
## Available methods - JAVA (0.0.2)v

- CnpjValidator
- cnpjIsValid

- CpfValidator
- cpfIsValid

CreditCardValidator
- isCreditCardValid
- identifyCreditCard

- EmailValidator
- isEmail

- Utils
- getOnlyEmail
- getOnlyEmailWithOptions (options)
- multiple (boolean) - default: false
- cleanDomain (boolean) - default: false
- repeatEmail (boolean) - default: false

- Validator
- isAscii
- isCEP
- isDate
- isDecimal
- isMACAddress
- isNumber
- isPort
- isPostalCode
- isTime


## How to use

### CnpjValidator
```java
import io.github.multiform_validator.Validator;
import io.github.multiform_validator.EmailValidator;
import io.github.multiform_validator.CpfValidator;
import io.github.multiform_validator.CnpjValidator;
import io.github.multiform_validator.Utils;

public class Main {
public static void main(String[] args) {
System.out.println(EmailValidator.isEmail("[email protected]")); // true
System.out.println(EmailValidator.isEmail("foo@bar")); // false
String cnpjTrue = "69.807.668/0001-41";
String cnpjFalse = "61.807.661/0001-48";
System.out.println(CnpjValidator.cnpjIsValid(cnpjTrue)); // true
System.out.println(CnpjValidator.cnpjIsValid(cnpjFalse)); // false
}
}
```

### CpfValidator
```java
import io.github.multiform_validator.CpfValidator;

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

System.out.println(CpfValidator.cpfIsValid("123.456.789-09")); // true
System.out.println(CpfValidator.cpfIsValid("123.456.789-00")); // false

System.out.println(CnpjValidator.cnpjIsValid("12.345.678/0001-09")); // true
System.out.println(CnpjValidator.cnpjIsValid("12.345.678/0001-00")); // false
### CreditCardValidator
```java
import io.github.multiform_validator.CreditCardValidator;

System.out.println(Validator.isAscii("foo")); // true
System.out.println(Validator.isAscii("foo©")); // false

System.out.println(Utils.getOnlyEmail("This is an example [email protected] bla yes my friend loren ipsun")); // [email protected]
System.out.println(Utils.getOnlyEmail("This is an example bla yes my friend loren ipsun")); // null
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
}
}
```

### EmailValidator
```java
import static io.github.multiform_validator.EmailValidator.isEmail;

public class Main {
public static void main(String[] args) {
String email = "[email protected]";
System.out.println(isEmail(email)); // 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 [email protected] email to test";
System.out.println(Utils.getOnlyEmail(msg1)); // [email protected]

String msg2 = "Example two [email protected] and [email protected]";
// With options
Utils.GetOnlyEmailOptionsParams options = new Utils.GetOnlyEmailOptionsParams();
options.multiple = true;
System.out.println(Utils.getOnlyEmail("This is an example [email protected] bla [email protected] yes yes", options)); // [[email protected], [email protected]]
System.out.println(Utils.getOnlyEmailWithOptions(msg2, options)); // [[email protected], [email protected]]
}
}
```

### 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
}

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
}
}
```
Expand Down

0 comments on commit 90a1215

Please sign in to comment.