Skip to content

Built-in Rules Catalog

Ctrovalidate provides a robust suite of validation rules out of the box. Rules are declarative, composable, and highly efficient.


🏗️ Composition Syntax

Rules are defined in the data-ctrovalidate-rules attribute.

  • Use a pipe (|) to separate rules: required|email
  • Use a colon (:) for parameters: minLength:8
  • Use commas (,) for multiple parameters: between:18,65

📋 General & Essential Rules

RuleDescriptionUsage Example
requiredField cannot be empty. For checkboxes, requires checked.required
emailValidates standard email formats.email
minLengthString must be $\ge$ specified length.minLength:8
maxLengthString must be $\le$ specified length.maxLength:250
exactLengthString must be exactly $N$ characters.exactLength:10
sameAsMust match the value of another field.sameAs:password

🔢 Numeric & Counting

RuleDescriptionUsage Example
numericAllows integers and decimals.numeric
integerAllows only whole numbers.integer
decimalRequires at least one decimal point.decimal
minNumber must be $\ge$ target.min:18
maxNumber must be $\le$ target.max:100
betweenNumber must be in range min,max.between:1,10

🔣 String & Format

RuleDescriptionUsage Example
alphaOnly letters (A-Z, a-z).alpha
alphaNumOnly letters and numbers.alphaNum
alphaDashLetters, numbers, -, and _.alphaDash
urlStandard URL format (requires protocol).url
phoneGeneral international phone format.phone
ipAddressValidates IPv4 format.ipAddress
jsonValidates JSON Object/Array string.json

🛡️ Security & Advanced

strongPassword

Ensures a baseline production security level:

  • Minimum 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one digit

Usage: data-ctrovalidate-rules="required|strongPassword"

creditCard

Validates credit card numbers using the Luhn Algorithm.

NOTE

This checks the format and mathematical validity, not the actual card balance or existence.

Usage: data-ctrovalidate-rules="required|creditCard"


💡 Pro-Tip: Rule Independence

Ctrovalidate treats rules as independent units. This means you can combine them in any order: required|numeric|min:18 is functionally identical to numeric|min:18|required.

Next Steps

Released under the MIT License.