Game Development Reference
In-Depth Information
an attractive feature designed to save time and effort, we'll focus on the functionality
that can best help us with respect to this auto validation.
Custom validation
One of the properties of
ValidState
is the Boolean
customError
, which specifies
whether a custom error message has been set to the field element or if the browser
is to display a generic error message for this element in case the form does not valid-
ate. To set a custom error message, we can call the
setCustomValidity()
meth-
od of the
form
element itself and assign a message for the browser to use when
needed, as follows:
var email = document.querySelector("#myForm
input[type='email']");
email.pattern = "\\w{3,}@packtpub\\.com";
email.setCustomValidity("Please enter a valid
Packt email address...");