As a best practice, we should add this attribute with Java Script so that if our script has an error or fails to load, the native browser form validation will still work.There may be some forms that you don't want to validate (for example, a search form that shows up on every page).
Whenever a user leaves a field, we want to check if it's valid. Rather than add a listener to every form field, we'll use a technique called event bubbling (or event propagation) to listen for all , the field is valid. See the Pen Form Validation: Validate On Blur by Chris Ferdinandi (@cferdinandi) on Code Pen.// If too short if (Short) return 'Please lengthen this text to ' Attribute('min Length') ' characters or more.You are currently using ' field.value.length ' characters.'; // If too long if (Long) return 'Please short this text to no more than ' Attribute('max Length') ' characters.Once we know there's an error, it's helpful to know what the error actually is.We can use the other Validity State properties to get that information.