1class Validator { 2 3 static rules = { 4 5 required(value){ 6 return value.trim() !== ''; 7 }, 8 9 email(value){ 10 return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value); 11 }, 12 13 phone(value){ 14 return /^[\+\d\s]{0,3}\({0,1}\d{3,4}[\)\s]{0,2}[\d\-\s]{7,11}$/.test(value); 15 }, 16 17 min(value, limit){ 18 return value.length >= limit; 19 }, 20 21 max(value, limit){ 22 return value.length <= limit; 23 }, 24 25 pattern(value, pattern){ 26 return new RegExp(pattern).test(value); 27 } 28 29 }; 30 31 static validate(input){ 32 33 const value = input.value; 34 35 for(const rule in this.rules){ 36 37 if(input.dataset[rule] !== undefined){ 38 39 const param = input.dataset[rule]; 40 41 const valid = this.rules[rule](value, param); 42 43 if(!valid){ 44 this.showError(input); 45 return false; 46 } else { 47 this.showPass(input); 48 } 49 50 } 51 52 } 53 54 this.clear(input); 55 return true; 56 57 } 58 59 static showError(input){ 60 61 const field = input.closest('.field'); 62 const text = input.dataset.validateText || 'ÐÑибка'; 63 64 field.classList.remove('has-passed'); 65 field.classList.add('has-error'); 66 field.dataset.error = text; 67 68 } 69 70 static showPass(input){ 71 72 const field = input.closest('.field'); 73 const text = ''; 74 75 field.classList.remove('has-error'); 76 field.classList.add('has-passed'); 77 field.dataset.error = text; 78 79 } 80 81 static clear(input){ 82 83 const field = input.closest('.field'); 84 85 if (field) { 86 field.classList.remove('has-error'); 87 delete field.dataset.error; 88 } 89 90 } 91 92}
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.