Complete example of building a user registration form validation with PolyVal
This guide demonstrates how to build a complete user registration validation system using PolyVal. We’ll cover username validation, email verification, password strength requirements, and terms acceptance.
PolyVal supports both en (English) and tr (Turkish) languages out of the box.
3
Customize error messages
Provide custom error messages for better user experience:
const customMessages = { required: "This field cannot be empty", string: { min: (min: number) => `At least ${min} characters required`, max: (max: number) => `Cannot exceed ${max} characters`, email: "Please enter a valid email address", regex: "Contains invalid characters" }, number: { min: (min: number) => `Must be at least ${min} years old` }, // Field-specific custom messages fields: { username: { min: (min: number) => `Username must have at least ${min} characters`, noAdminUsername: "Sorry, 'admin' is a reserved username" }, password: { min: (min: number) => `Password must be at least ${min} characters long`, regex: "Password must include uppercase, lowercase, number and special character" }, confirmPassword: { equals: "Passwords do not match" }, acceptTerms: { equals: "You must accept the terms and conditions" } }};const errorsEN = validate(userRegistrationSchema, invalidData, { lang: 'en', customMessages});errorsEN.forEach((error: string) => console.log(`- ${error}`));