From 1cac7b11dc323e671cc713bce7610a235acced2d Mon Sep 17 00:00:00 2001 From: gabriel-logan <gabrielcoutolima@protonmail.ch> Date: Thu, 11 Jul 2024 10:08:20 -0300 Subject: [PATCH] feat: Add email validation examples to Main class --- .idea/workspace.xml | 29 +---------------------------- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0e6ea1e..2cc4aef 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,34 +4,7 @@ <option name="autoReloadType" value="SELECTIVE" /> </component> <component name="ChangeListManager"> - <list default="true" id="22c9667a-e00d-49e2-aa6d-da35dd213aa7" name="Changes" comment=""> - <change afterPath="$PROJECT_DIR$/src/main/java/io/github/multiform_validator/Validate.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/5/8/588b78f1e6cd56164975813197d21c04f270e038" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/5/8/588b78f1e6cd56164975813197d21c04f270e038" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/5/a/5a503c465e2e403dbd4c3fe2906c7cecc8e13602" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/5/a/5a503c465e2e403dbd4c3fe2906c7cecc8e13602" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/d/c/dcba94fd99e9396082d1fedd3522764f78825365" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/d/c/dcba94fd99e9396082d1fedd3522764f78825365" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/f/9/f9465a1df802c670887a6edc9706fd150e19342b" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/f/9/f9465a1df802c670887a6edc9706fd150e19342b" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/issuestore/index.pb" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/sonarlint/securityhotspotstore/index.pb" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/sonarlint/securityhotspotstore/index.pb" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/io/github/multiform_validator/EmailValidator.java" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/main/java/io/github/multiform_validator/Validator.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/io/github/multiform_validator/Validator.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/test/java/EmailValidatorTest.java" beforeDir="false" /> - <change beforePath="$PROJECT_DIR$/src/test/java/UtilsTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/UtilsTest.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/src/test/java/ValidatorTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ValidatorTest.java" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" beforeDir="false" afterPath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" beforeDir="false" afterPath="$PROJECT_DIR$/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/CnpjValidatorTest.txt" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/CnpjValidatorTest.txt" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/CpfValidatorTest.txt" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/CpfValidatorTest.txt" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/CreditCardValidatorTest.txt" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/CreditCardValidatorTest.txt" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/TEST-CnpjValidatorTest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/TEST-CnpjValidatorTest.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/TEST-CpfValidatorTest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/TEST-CpfValidatorTest.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/TEST-CreditCardValidatorTest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/TEST-CreditCardValidatorTest.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/TEST-UtilsTest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/TEST-UtilsTest.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/TEST-ValidatorTest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/TEST-ValidatorTest.xml" afterDir="false" /> - <change beforePath="$PROJECT_DIR$/target/surefire-reports/ValidatorTest.txt" beforeDir="false" afterPath="$PROJECT_DIR$/target/surefire-reports/ValidatorTest.txt" afterDir="false" /> - </list> + <list default="true" id="22c9667a-e00d-49e2-aa6d-da35dd213aa7" name="Changes" comment="" /> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> diff --git a/README.md b/README.md index 09b1dfc..412cba0 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,51 @@ public class Main { } ``` +### Validate + +```java +import io.github.multiform_validator.Validate; +import io.github.multiform_validator.Validate.ValidateEmailOptionsParams; + +public class Main { + public static void main(String[] args) { + validateEmailExample(); + } + + public static void validateEmailExample() { + // 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.maxLength = 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.country = "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.validDomains = 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.validDomainsList.add("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