CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vuelidate--validators

Comprehensive validation library for Vue.js applications providing common validators with built-in error messages and customization options

87

1.14x
Overview
Eval results
Files

task.mdevals/scenario-7/

User Registration Form Validator

Build a user registration form validator that validates user input according to specific business rules.

Requirements

Create a validation system for a user registration form with the following fields:

Required Fields

All of the following fields must be present:

  • Username
  • Email address
  • Age
  • Website URL (optional)
  • Password
  • Password confirmation

Validation Rules

  1. Username: Must be provided and contain only alphanumeric characters
  2. Email: Must be provided and be a valid email format
  3. Age: Must be provided, be numeric, and be at least 18
  4. Website URL: If provided, must be a valid URL format (optional field)
  5. Password: Must be provided and be at least 8 characters long
  6. Password Confirmation: Must be provided and match the password field

Implementation

Create a function called createUserValidation that returns a validation rules object suitable for use with a validation library. The function should accept a form data object (or reactive ref) as its parameter.

The validation rules should cover all the requirements listed above.

@generates

Test Cases

  • It validates that username is required @test
  • It validates that username contains only alphanumeric characters @test
  • It validates that email is required @test
  • It validates that email has valid format @test
  • It validates that age is required @test
  • It validates that age is numeric @test
  • It validates that age is at least 18 @test
  • It validates that website URL has valid format when provided @test
  • It allows empty website URL since it is optional @test
  • It validates that password is required @test
  • It validates that password has minimum length of 8 @test
  • It validates that password confirmation matches password @test

API

/**
 * Creates validation rules for a user registration form
 * @param {Object} formData - The form data object containing user input fields
 * @returns {Object} Validation rules object
 */
export function createUserValidation(formData) {
  // Implementation here
}

Dependencies { .dependencies }

@vuelidate/validators { .dependency }

Provides validation functions for common validation scenarios including required fields, email format, numeric values, URL format, string length constraints, and field matching.

Install with Tessl CLI

npx tessl i tessl/npm-vuelidate--validators

tile.json