Validation rules supported by internal.js
Validation Rules Cheat Sheet
Section titled “Validation Rules Cheat Sheet”Add these strings to the rules array inside an element’s data-validate JSON to activate the corresponding behaviour. Multiple rules can be combined; they are applied in order.
| Rule | Purpose | Example |
|---|---|---|
noSpaces | Strip all whitespace characters. | ["noSpaces"] |
digits | Allow only numbers. If noDecimals is not present, a single . is allowed. | ["digits"] |
fixedDigits:n | Force exactly n digits (non-numeric characters removed). Marks valid only when the length is reached. | ["fixedDigits:10"] for a 10-digit phone |
range:min-max | Value must be within numeric range (inclusive). | ["range:1-100"] |
positive | Remove - sign to keep value positive. | ["positive"] |
noDecimals | Remove any decimal points. Often paired with digits. | ["digits","noDecimals"] |
fixedDecimals:n | Clamp decimal portion to n places; marks valid when exactly n decimals are present. | ["digits","fixedDecimals:2"] for currency |
upperCase / lowerCase | Force casing on the entire value. | ["upperCase"] |
nonZero | Clears the value if it equals "0". | ["nonZero"] |
noLeadingZeros | Removes extra zeros at the start (e.g., 0012 → 12). | ["noLeadingZeros"] |
minLength:n | Valid only when the trimmed value has at least n characters. | ["minLength:3"] |
maxLength:n | Truncate value to n characters. | ["maxLength:25"] |
exactLength:n | Valid only when the value is exactly n characters. | ["exactLength:6"] |
email | Basic email pattern validation. | ["email"] |
url | Basic HTTP/HTTPS URL check. | ["url"] |
phone | Allows optional + followed by digits. | ["phone"] |
date | Requires YYYY-MM-DD. | ["date"] |
dateRange:YYYY-MM-DD-YYYY-MM-DD | Ensures the date falls within the provided range. | ["date","dateRange:2024-01-01-2024-12-31"] |
futureDate / pastDate | Date must be after/before today. (Use with date.) | ["date","futureDate"] |
time | Accepts HH:MM in 24-hour format. | ["time"] |
Example JSON
Section titled “Example JSON”<input id="input_pan" data-validate='{ "rule_name":"kycBlock", "rules":["upperCase","exactLength:10","noSpaces"], "required":true, "show_error":true, "error_header":"Invalid PAN", "error_text":"PAN must be 10 characters (letters/numbers only)", "valid":false }'/>- Rules run in the order listed; place sanitising rules (
noSpaces,digits) before validators (minLength,range) so the checks see cleaned values. - You can mix rule types—for example,
["digits","fixedDigits:6","range:100000-999999"]ensures a six-digit OTP within a numeric window. - Dropdowns typically use validation for presence (
required) rather than format, but you can still sharerule_namewith inputs so buttons enable as a group.