Skip to content

Validation rules supported by internal.js

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.

RulePurposeExample
noSpacesStrip all whitespace characters.["noSpaces"]
digitsAllow only numbers. If noDecimals is not present, a single . is allowed.["digits"]
fixedDigits:nForce exactly n digits (non-numeric characters removed). Marks valid only when the length is reached.["fixedDigits:10"] for a 10-digit phone
range:min-maxValue must be within numeric range (inclusive).["range:1-100"]
positiveRemove - sign to keep value positive.["positive"]
noDecimalsRemove any decimal points. Often paired with digits.["digits","noDecimals"]
fixedDecimals:nClamp decimal portion to n places; marks valid when exactly n decimals are present.["digits","fixedDecimals:2"] for currency
upperCase / lowerCaseForce casing on the entire value.["upperCase"]
nonZeroClears the value if it equals "0".["nonZero"]
noLeadingZerosRemoves extra zeros at the start (e.g., 001212).["noLeadingZeros"]
minLength:nValid only when the trimmed value has at least n characters.["minLength:3"]
maxLength:nTruncate value to n characters.["maxLength:25"]
exactLength:nValid only when the value is exactly n characters.["exactLength:6"]
emailBasic email pattern validation.["email"]
urlBasic HTTP/HTTPS URL check.["url"]
phoneAllows optional + followed by digits.["phone"]
dateRequires YYYY-MM-DD.["date"]
dateRange:YYYY-MM-DD-YYYY-MM-DDEnsures the date falls within the provided range.["date","dateRange:2024-01-01-2024-12-31"]
futureDate / pastDateDate must be after/before today. (Use with date.)["date","futureDate"]
timeAccepts HH:MM in 24-hour format.["time"]
<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 share rule_name with inputs so buttons enable as a group.