Skip to content

Ms-Sandy-A/my-form-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Form Validation with Tailwind CSS

A simple and beginner-friendly form validation example using HTML, Tailwind CSS, and JavaScript.

Features

  • ✅ Real-time validation as you type
  • ✅ Visual feedback with red/green borders
  • ✅ Error messages below each field
  • ✅ Responsive design
  • ✅ Clean and modern UI

How to Use

  1. Open the file: Simply open index.html in your web browser
  2. Test the form: Try filling out the form fields to see validation in action
  3. Validation rules:
    • Name: Must be at least 2 characters
    • Email: Must be a valid email format
    • Phone: Must be a valid phone number
    • Password: Must be at least 8 characters
    • Confirm Password: Must match the password

HTML Structure

  • Each input field has a label and an error message div
  • Form uses Tailwind CSS classes for styling
  • Inputs have focus states and transitions

CSS (Tailwind)

  • Uses Tailwind's utility classes for styling
  • Custom CSS for error/success states
  • Responsive design with max-w-md

JavaScript

  • Validation functions: Check if input is valid
  • Event listeners: Trigger validation when user leaves a field (blur event)
  • Visual feedback: Add/remove CSS classes for error/success states
  • Form submission: Prevent submission if any field is invalid

Key Concepts for Beginners

  1. Event Listeners: JavaScript listens for when users interact with the form
  2. DOM Manipulation: We change the appearance of elements based on validation
  3. Regular Expressions: Used to validate email and phone formats
  4. CSS Classes: We add/remove classes to show different states

Customization

You can easily customize this form by:

  • Changing colors in the Tailwind classes
  • Adding more validation rules
  • Modifying the error messages
  • Adding more form fields

Browser Support

Works in all modern browsers that support:

  • ES6 JavaScript
  • CSS Grid/Flexbox
  • Tailwind CSS

Next Steps

Once you understand this example, you can:

  • Add more complex validation rules
  • Connect it to a backend server
  • Add loading states
  • Implement password strength indicators
  • Add more form fields

About

a form validation built with HTML , Tailwind CSS ,and JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages