Const
Parses a human-readable string to extract a set of validation rules.
It identifies keywords for common validation requirements (e.g., "required", "strong password")
and also leverages parseHumanTextToRegex
to create pattern-based rules.
The natural language string describing the validation requirements.
Optional
testValue: stringAn optional string to test the extracted rules against.
A ValidationExtractionResult
object containing the rules, confidence, and other metadata.
Textual description of validation needs and constraints. Supports complex scenarios: "mandatory email with custom domain", "secure password with mixed case and symbols", "conditional phone number format"
Optional sample input for immediate rule testing and validation. Provides real-time feedback on whether the input meets the described requirements.
Detailed ValidationExtractionResult
with comprehensive validation data:
success
: Indicates whether meaningful validation rules were extractedrules
: Structured array of validation rules with patterns and custom validatorsconfidence
: Numeric confidence score reflecting extraction accuracydescription
: Human-friendly summary of the validation requirementssuggestions
: Constructive guidance for improving validation or input formatallPassed
: Overall validation status when test value is providedcaseUnPassed
: Specific validation rules that failed (helps with debugging)// Form field validation
const usernameRules = textToValidation("required username 3-20 characters alphanumeric only");
// Multi-constraint validation
const complexRules = textToValidation("password minimum 12 characters with uppercase lowercase numbers symbols");
// Real-time validation feedback
const validation = textToValidation("required credit card", "4532-1234-5678-9012");
validation.rules.forEach(rule => {
if (rule.pattern && !rule.pattern.test("4532-1234-5678-9012")) {
console.log(`Failed: ${rule.message}`);
}
});
Converts descriptive text into structured validation rule sets. This practical alias for
parseHumanTextToValidation
specializes in transforming textual validation requirements into actionable validation logic with error messages.