1"use strict"; 2 3document.addEventListener('DOMContentLoaded', function () { 4 var commentForm = document.getElementById('commentform'); 5 if (!commentForm) return; 6 var fields = [{ 7 name: 'author' 8 }, { 9 name: 'email', 10 validate: validateEmail 11 }, { 12 name: 'comment' 13 }]; 14 commentForm.addEventListener('submit', function (event) { 15 var valid = true; 16 fields.forEach(function (field) { 17 var input = document.querySelector("[name=\"".concat(field.name, "\"]")); 18 if (!input) return; 19 var error = input.parentNode.querySelector('span'); 20 if (error) { 21 error.style.display = 'none'; 22 error.classList.remove('error'); 23 } 24 if (input.value.trim() === '') { 25 if (error) { 26 error.style.display = 'inline'; 27 error.classList.add('error'); 28 } 29 valid = false; 30 } else if (field.validate && !field.validate(input.value)) { 31 if (error) { 32 error.textContent = 'Please enter a valid email'; 33 error.style.display = 'inline'; 34 error.classList.add('error'); 35 } 36 valid = false; 37 } 38 }); 39 if (!valid) { 40 event.preventDefault(); 41 } 42 }); 43 function validateEmail(email) { 44 var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; 45 return re.test(String(email).toLowerCase()); 46 } 47});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.