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-2/

User Registration Form Validator

Build a user registration form validation system for a Vue.js application. The form should validate user input in real-time and provide clear feedback about validation status.

Requirements

Create a Vue component that validates a user registration form with the following fields:

  1. Username: Must be provided and contain only alphanumeric characters
  2. Email: Must be provided and be a valid email format
  3. Password: Must be provided and be at least 8 characters long
  4. Confirm Password: Must be provided and match the password field

The component should:

  • Track validation state for each field
  • Show whether each field is valid or invalid
  • Only show errors for fields that have been touched/interacted with
  • Provide a method to validate the entire form manually
  • Expose the overall form validity status

Test Cases

  • The username field is invalid when empty @test
  • The username field is invalid when it contains non-alphanumeric characters @test
  • The email field is invalid when empty @test
  • The email field is invalid when it doesn't match email format @test
  • The password field is invalid when it has fewer than 8 characters @test
  • The confirm password field is invalid when it doesn't match the password @test
  • Fields marked as dirty show their error state correctly @test
  • The form can be validated manually @test

Implementation

@generates

API

/**
 * Returns a reactive validation object for the registration form.
 *
 * @param {Object} formData - The reactive form data object with username, email, password, and confirmPassword fields
 * @returns {Object} Validation object with validation state and methods
 */
function useRegistrationValidation(formData) {
  // Returns validation object with:
  // - Field-level validation states (username, email, password, confirmPassword)
  // - Each field has: $invalid, $dirty, $error properties
  // - Methods: $touch(), $validate()
  // - Overall form state: $invalid
}

export { useRegistrationValidation };

Dependencies { .dependencies }

@vuelidate/core { .dependency }

Provides validation setup and state management functionality.

@vuelidate/validators { .dependency }

Provides built-in validators for common validation patterns.

Install with Tessl CLI

npx tessl i tessl/npm-vuelidate--validators

tile.json