Native form validation — part 2
Peter-Paul Koch
551

One additional use case/thing you may want to do with native form validation: use the browser’s built-in validation methods (so you don’t have to write your own regexps to check if, say, an email address smells like a real email address), but still show your own custom (non native) error message (and if native validation is not supported, conditionally load in an external custom JS validation library of sorts). For this, it’s useful to know that you can access the string that the browser would normally show in its native validation/error bubble using the validationMessage property…so you could do something like (using console.log as a dumb example): if (foo.validity.valid) { console.log(foo.validationMessage); }

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.