Javascript examples for DOM Event:oninvalid
Check if an input field contains less than 6 characters:
<!DOCTYPE html> <html> <body> <form action="/action_page.php" method="get"> Name: <input type="text" id="myInput" name="fname" pattern=".{6,}"> <input type="submit" value="Submit"> </form>/*from w ww . j a v a 2s . co m*/ <script> document.getElementById("myInput").addEventListener("invalid", myFunction); function myFunction() { console.log("Must contain 6 or more characters"); } </script> </body> </html>