Back to course

Lesson 33: Form Validation Attributes (Required, Pattern)

The HTML Masterclass: From Zero to Web Developer

33. Form Validation Attributes

HTML allows us to define basic validation rules directly in the markup, which provides a fast, initial layer of client-side validation before the data even reaches the server.

33.1 The required Attribute

If present, the user must fill out the field before submitting the form. If left empty, the browser displays a standard error message.

html

33.2 Minimum and Maximum Length (minlength, maxlength)

Used for text inputs to define the acceptable number of characters.

html

33.3 The pattern Attribute (Regular Expressions)

The pattern attribute allows you to specify a Regular Expression (RegEx) that the input value must match. This is used for complex validation, like zip codes or custom formats.

html

Note: title is important here, as it provides a tooltip to the user explaining the required format.