Skip to content

Built-in Rules Catalog

Ctrovalidate provides 21 built-in validation rules out of the box. Rules are declarative, composable, and can be combined in any order.


🏗️ 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

🔣 Format & Pattern Rules

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 and IPv6 formats.ipAddress
jsonValidates JSON Object/Array string.json
creditCardValidates credit card using Luhn Algorithm.creditCard

💡 Rule Composition

Rules are independent and can be combined in any order:

  • required|numeric|min:18 is identical to numeric|min:18|required
  • All rules are executed in the order they appear
  • Validation stops at the first failing rule

Total: 21 Built-in Rules

  • Common Rules (6): required, email, minLength, maxLength, exactLength, sameAs
  • Numeric Rules (6): numeric, integer, decimal, min, max, between
  • Format Rules (9): alpha, alphaNum, alphaDash, url, phone, ipAddress, json, creditCard

Next Steps

Released under the MIT License.