Html5 form validation
How do I make an html5 form validation?
Uses HTML5 form validation api without jquery. Tested in Chrome.. What is a html5 form validation? How do you make a html5 form validation? This script and codes were developed by Rob on 30 August 2022, Tuesday.
Html5 form validation - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>html5 form validation</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <form method="post" id="theform"> <label for="name"> Name <br/> <input type="text" name="name" required></input> <p class="errorText hidden">error</p> </label> <label for="phone">Phone<br/> <input type="tel" name="phone" pattern="\d{1,3}\s?\d{3,4}\s?\d{3,5}" required></input> <p class="errorText hidden">error</p> </label> <label for="email">email <br/> <input type="email" name="email" required></input> <p class="errorText hidden">error</p> </label> <button type="submit" id="submitform">submit</button> <div id="errors"></div>
</form> <script src="js/index.js"></script>
</body>
</html>
Html5 form validation - Script Codes CSS Codes
form { font-family: arial; font-size: 13px;
}
label { display: block;
}
input { display: inline-block; margin-bottom: 20px;
}
.errorText { color: red; display: inline-block; margin: 0;
}
.hidden { display: none;
}
Html5 form validation - Script Codes JS Codes
var button = document.getElementById('submitform');
button.addEventListener('click', function(event){ event.preventDefault(); validator.showErrors(this.parentNode.elements);
});
var validator = { showErrors: function(formFields) { for(var i = 0; i < formFields.length; i++) { if(!formFields[i].checkValidity()) { // this part might not work in other browsers formFields[i].nextSibling.nextSibling.classList.remove('hidden'); } else { formFields[i].nextSibling.nextSibling.classList.add('hidden'); } } }
};
Developer | Rob |
Username | rowinf |
Uploaded | August 30, 2022 |
Rating | 3 |
Size | 2,090 Kb |
Views | 46,552 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Bootstrap test | 1,906 Kb |
A Pen by Rob | 1,972 Kb |
Flash Cards | 3,086 Kb |
Nav Menu with Chevron | 1,966 Kb |
Table filters | 1,727 Kb |
Get combo box item value | 1,981 Kb |
Jquery form | 2,920 Kb |
Responsive Calendar | 2,460 Kb |
Filter inputs | 1,721 Kb |
Site Layout | 3,219 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Right Click Menu | Anodpixels | 2,252 Kb |
Css3 slide | Nakome | 3,190 Kb |
Menu | Vivi_Lai | 1,210 Kb |
Twitch Live Channels | Inkblotty | 4,956 Kb |
Drag n Drop | Martin42 | 2,594 Kb |
Iron Man SVG Loading Animation | Andythayer | 3,069 Kb |
Loading animation | Hafizfattah | 0 Kb |
Wikipedia viewer | Chpecson | 2,865 Kb |
Count up | Alanshortis | 2,391 Kb |
The Walking Raymarcher | Xorxor_hu | 7,934 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!