Check if an input field contains less than 6 characters: - Javascript DOM Event

Javascript examples for DOM Event:oninvalid

Description

Check if an input field contains less than 6 characters:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials