Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ApamateSoft/Validator/llms.txt
Use this file to discover all available pages before exploring further.
The Alphabets class provides a set of predefined character strings that can be used with validation rules like shouldOnlyContain, notContain, and mustContainOne. These constants make it easy to validate that input contains only specific types of characters.
Import
import io.github.ApamateSoft.validator.utils.Alphabets;
Available Alphabets
Numeric Systems
BIN
Binary digits (base-2)
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.BIN, "Must contain only binary digits")
.build();
validator.isValid("101010"); // Valid
validator.isValid("102"); // Invalid - contains '2'
OCT
Octal digits (base-8)
Alphabets.OCT = "01234567"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.OCT, "Must contain only octal digits")
.build();
validator.isValid("755"); // Valid
validator.isValid("789"); // Invalid - contains '8' and '9'
HEX
Hexadecimal digits (base-16)
Alphabets.HEX = "0123456789aAbBcCdDeEfF"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.HEX, "Must contain only hexadecimal digits")
.build();
validator.isValid("1a2B3c"); // Valid
validator.isValid("GGFF00"); // Invalid - contains 'G'
English Alphabets
NUMBER
Numeric digits (0-9)
Alphabets.NUMBER = "0123456789"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.NUMBER, "Must contain only numbers")
.build();
validator.isValid("12345"); // Valid
validator.isValid("12-345"); // Invalid - contains '-'
ALPHABET
English letters (mixed case)
Alphabets.ALPHABET = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHABET, "Must contain only letters")
.build();
validator.isValid("JohnDoe"); // Valid
validator.isValid("John123"); // Invalid - contains numbers
ALPHA_LOWERCASE
Lowercase English letters
Alphabets.ALPHA_LOWERCASE = "abcdefghijklmnopqrstuvwxyz"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_LOWERCASE, "Must contain only lowercase letters")
.build();
validator.isValid("johndoe"); // Valid
validator.isValid("JohnDoe"); // Invalid - contains uppercase
ALPHA_UPPERCASE
Uppercase English letters
Alphabets.ALPHA_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_UPPERCASE, "Must contain only uppercase letters")
.build();
validator.isValid("ABCD"); // Valid
validator.isValid("AbCd"); // Invalid - contains lowercase
ALPHA_NUMERIC
English letters and numbers
Alphabets.ALPHA_NUMERIC = "0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_NUMERIC, "Must contain only letters and numbers")
.build();
validator.isValid("User123"); // Valid
validator.isValid("User_123"); // Invalid - contains '_'
Spanish Alphabets
These alphabets include Spanish-specific characters like ñ, á, é, í, ó, ú.
ALPHABET_ES
Spanish letters (mixed case) with accents
Alphabets.ALPHABET_ES = "aAáÁbBcCdDeEéÉfFgGhHiIíÍjJkKlLmMnNñÑoOóÓpPqQrRsStTuUúÚvVwWxXyYzZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHABET_ES, "Must contain only Spanish letters")
.build();
validator.isValid("José"); // Valid
validator.isValid("Peña"); // Valid
validator.isValid("José123"); // Invalid - contains numbers
ALPHA_LOWERCASE_ES
Lowercase Spanish letters with accents
Alphabets.ALPHA_LOWERCASE_ES = "aábcdeéfghiíjklmnñoópqrstuúvwxyz"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_LOWERCASE_ES, "Must contain only lowercase Spanish letters")
.build();
validator.isValid("josé"); // Valid
validator.isValid("José"); // Invalid - contains uppercase
ALPHA_UPPERCASE_ES
Uppercase Spanish letters with accents
Alphabets.ALPHA_UPPERCASE_ES = "AÁBCDEÉFGHIÍJKLMNÑOÓPQRSTUÚVWXYZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_UPPERCASE_ES, "Must contain only uppercase Spanish letters")
.build();
validator.isValid("JOSÉ"); // Valid
validator.isValid("José"); // Invalid - contains lowercase
ALPHA_NUMERIC_ES
Spanish letters (with accents) and numbers
Alphabets.ALPHA_NUMERIC_ES = "0123456789aAáÁbBcCdDeEéÉfFgGhHiIíÍjJkKlLmMnNñÑoOóÓpPqQrRsStTuUúÚvVwWxXyYzZ"
Example:
Validator validator = new Validator.Builder()
.shouldOnlyContain(Alphabets.ALPHA_NUMERIC_ES, "Must contain only Spanish letters and numbers")
.build();
validator.isValid("Código123"); // Valid
validator.isValid("Code-123"); // Invalid - contains '-'
Usage with Validation Rules
Alphabets are most commonly used with these validation rules:
shouldOnlyContain
Validate that input contains only characters from the alphabet:
Validator passwordValidator = new Validator()
.shouldOnlyContain(Alphabets.ALPHA_NUMERIC + "_-", "Password must contain only letters, numbers, hyphens, and underscores")
.build();
notContain
Validate that input does not contain any characters from the alphabet:
Validator usernameValidator = new Validator()
.notContain("!@#$%^&*()", "Username cannot contain special characters");
mustContainOne
Validate that input contains at least one character from the alphabet:
Validator passwordValidator = new Validator()
.mustContainOne(Alphabets.NUMBER, "Password must contain at least one number")
.mustContainOne(Alphabets.ALPHA_UPPERCASE, "Password must contain at least one uppercase letter");
mustContainMin
Validate that input contains a minimum number of characters from the alphabet:
Validator passwordValidator = new Validator()
.mustContainMin(2, Alphabets.NUMBER, "Password must contain at least 2 numbers");
Custom Alphabets
You can also create your own custom alphabets for specific validation needs:
// Custom alphabet for vowels only
String vowels = "aeiouAEIOU";
Validator validator = new Validator.Builder()
.shouldOnlyContain(vowels, "Must contain only vowels")
.build();
// Custom alphabet for common safe URL characters
String urlSafe = Alphabets.ALPHA_NUMERIC + "-._~";
Validator urlValidator = new Validator()
.shouldOnlyContain(urlSafe, "Must be URL-safe")
.build();
// Custom alphabet combining multiple predefined sets
String passwordChars = Alphabets.ALPHA_NUMERIC + "!@#$%^&*()";
Validator passwordValidator = new Validator()
.shouldOnlyContain(passwordChars, "Password contains invalid characters")
.build();
Use Cases
Password Validation
Validator passwordValidator = new Validator()
.required("Password is required")
.minLength(8, "Password must be at least 8 characters")
.mustContainOne(Alphabets.ALPHA_LOWERCASE, "Must contain a lowercase letter")
.mustContainOne(Alphabets.ALPHA_UPPERCASE, "Must contain an uppercase letter")
.mustContainOne(Alphabets.NUMBER, "Must contain a number")
.mustContainOne("!@#$%^&*()", "Must contain a special character");
Username Validation
Validator usernameValidator = new Validator()
.required("Username is required")
.rangeLength(3, 20, "Username must be 3-20 characters")
.shouldOnlyContain(Alphabets.ALPHA_NUMERIC + "_", "Username can only contain letters, numbers, and underscores")
.notContain(Alphabets.ALPHA_UPPERCASE, "Username must be lowercase");
Color Hex Code Validation
Validator hexColorValidator = new Validator()
.required("Color code is required")
.length(6, "Color code must be exactly 6 characters")
.shouldOnlyContain(Alphabets.HEX, "Must be a valid hexadecimal color code")
.build();
Spanish Name Validation
Validator nombreValidator = new Validator()
.required("Nombre es requerido")
.shouldOnlyContain(Alphabets.ALPHABET_ES + " ", "El nombre solo puede contener letras españolas y espacios")
.build();