Data-attribute driven validation with real-time feedback, powered by Sadrazam.Form
The validation system is driven entirely by HTML data attributes -- no extra JS wiring needed per field
Available rules: required email min_length:N max_length:N min_value:N max_value:N matches:fieldName not_match:fieldName less_than:fieldName greater_than:fieldName regex:pattern
The required rule works on text inputs, selects, checkboxes, and radio buttons. Submit the empty form to see errors.
Combine required with email to enforce both presence and format. The email rule uses the pattern /^[^\s@]+@[^\s@]+\.[^\s@]+$/.
Use min_length:N and max_length:N to constrain character count. Validation is debounced at 300ms during live typing.
Use min_value:N and max_value:N for numeric range validation. Also supports less_than:fieldName and greater_than:fieldName for cross-field comparison.
Use matches:fieldName to ensure two fields have the same value (e.g. password confirmation). Use not_match:fieldName to ensure they differ (e.g. new password vs old password).
Use regex:pattern for custom patterns. The value after regex: is passed directly to new RegExp().
Control where and how error messages appear using data-form-validate-display and data-form-validate-message.
Add data-form-validate-message on the <form> element itself to show a summary message when validation fails. Use data-form-validate-display to control where it appears.
Call Sadrazam.Form.validate(element) directly on a form or a single input for custom validation flows outside of form submission.
Use Sadrazam.Form.togglePasswordVisibility(button) to toggle between password and text input types. The button must be the next sibling of the input.
A realistic example combining multiple validation rules: required, email, min_length, matches, regex, and custom messages.
Disabled inputs are automatically skipped during validation. Errors are cleared when a field becomes disabled. Toggle the checkbox to enable/disable the input and try submitting.