├── .gitignore ├── README.md ├── bower.json ├── dev ├── inspect.js └── lang-inspect │ ├── en.json │ ├── es.json │ ├── pt-br.json │ └── pt.json ├── dist ├── inspect.min.js └── lang-inspect │ ├── en.json │ ├── es.json │ ├── pt-br.json │ └── pt.json ├── example.gif ├── gulpfile.js ├── index.html ├── license-gpl-v2.md ├── license-mit.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | index.html 2 | script.js 3 | node_modules/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Inspect 2 | Form validation in Javascript Vanilla, without dependencies and multiple languages. ~8kb 3 | 4 | [DEMO PAGE - http://ktquez.github.io/Inspect/](http://ktquez.github.io/Inspect/) 5 | 6 | ![alt tag](https://cloud.githubusercontent.com/assets/8084606/13711641/6b5a910e-e79e-11e5-927f-b38ee3f9a0e7.gif) 7 | 8 | ## How to use 9 | ### npm 10 | ```shell 11 | npm install inspect-form --save 12 | ``` 13 | 14 | ### bower 15 | ```shell 16 | bower install inspect-form --save 17 | ``` 18 | 19 | Include the script of the Inspect on your page 20 | ```html 21 | 22 | ... 23 | 24 | ``` 25 | 26 | ## Create your form 27 | ```html 28 |
29 |
30 | 31 | 32 |
33 |
34 | 35 | 36 |
37 | 38 |
39 | ``` 40 | 41 | ### Attributes 42 | `` data-rules `` : The rules that will apply to the field
43 | **Info:** You can use more than one rule, for it must use the pipe, for examplo: `` required|number|cpf `` 44 | 45 | `` data-msg-custom `` ***Opcional*** : Text, if you want to customize the output of the error message
46 | **Info:** If it was not informed msn Custom, the field name will be used 47 | 48 | ### Rules 49 | * **required** -- Required field, not empty
50 | * **email** -- Check a valid email address 51 | * **max** -- Limit the maximum value, for examplo: `` required|max:10 ``. 52 | * **min** -- Limit the minimum value, for examplo: `` min:2 ``. 53 | * **card** -- Checks if the credit card is entered correctly, 16 digits 54 | * **number** -- Checks if the value is a number 55 | * **url** -- Checks if the URL is entered correctly 56 | 57 | #### Specific Brazil 58 | * **cpfCnpf** -- Checks if the value is a valid CPF or CNPJ 59 | * **cpf** -- Checks if the value is a valid CPF, 11 digits 60 | * **cnpj** -- Checks if the value is a valid CNPJ, 14 digits 61 | * **cep** -- Checks if the CEP is entered correctly, format pt-BR (XXXXX-XXX) 62 | 63 | ## Defining the form on Inspect 64 | Instantiates the form only through the name the form 65 | ```js 66 | var myForm = new Inspect('formTest'); 67 | ``` 68 | 69 | Instance the form through the settings 70 | ```js 71 | var myForm = new Inspect({ 72 | 'form' : 'formTest', 73 | 'touched' : true, 74 | 'tooltip' : true 75 | }); 76 | ``` 77 | 78 | ### Settings 79 | Currently you can customize some inspect actions, customize how the form will be validated or even choose the type of alert. 80 | 81 | * **form:** -- Name the form 82 | * **touched:** -- If you want the Inspect check, when the user take the focus off the field, default : false 83 | * **tooltip:** -- If you want to use the alert more friendly, default : false 84 |
**Info:** By default the alerts are simple, you can customize through its style css, simple alert structure created: 85 | ```html 86 |
87 | O Campo Nome é obrigatório 88 |
89 | ``` 90 | Just customize the classes available, ``inspect-message`` and ``inspect-message-text`` 91 | 92 | ## Performing validation with the created instances 93 | For validations and data prepared for AJAX requests, use the following syntax: 94 | ```js 95 | var myForm = new Inspect('formTest'); 96 | myForm.make(function(data){ 97 | // your code here (for example: AJAX requests) 98 | }); 99 | ``` 100 | 101 | For normal implementation of the form 102 | ```js 103 | var myForm = new Inspect('formTest'); 104 | myForm.toSubmit(); 105 | ``` 106 | 107 | ### Reset form 108 | If you need to empty the form, simply use the function `` myForm.pristine(); `` 109 | For example: 110 | ```js 111 | var myForm = new Inspect('formTest'); 112 | myForm.make(function(data){ 113 | myForm.pristine(); // Reset 114 | // your code here (for example: AJAX requests) 115 | }); 116 | ``` 117 | 118 | ### Short Syntax 119 | ```js 120 | new Inspect('formTest').toSubmit(); 121 | ``` 122 | Or 123 | ```js 124 | new Inspect({ 125 | 'form' : 'formTest', 126 | 'tooltip' : true 127 | }).make(function(data){ 128 | // your code here (for example: AJAX requests) 129 | }); 130 | ``` 131 | 132 | ## For more than one form per page 133 | ```js 134 | var myForm = new Inspect('formTest') 135 | myForm.toSubmit(); 136 | 137 | var myForm2 = new Inspect({ 138 | 'form' : 'formTest2', 139 | 'tooltip' : true 140 | }); 141 | myForm2.make(function(){ 142 | // your code here (for example: AJAX requests) 143 | }); 144 | 145 | var myForm3 = new Inspect({ 146 | 'form' : 'formTest3', 147 | 'tooltip' : true 148 | }) 149 | myForm3.toSubmit(); 150 | ``` 151 | 152 | ## Languages 153 | At the time the error messages are only available in: 154 | * **pt-br** -- Portuguese BR 155 | * **pt** -- Portuguese 156 | * **en** -- English 157 | * **es** -- Spanish 158 | 159 | **Alert:** - Keep lang directory in the same location as the file inspect.min.js, to load the translation via ajax is successful. 160 | 161 | ### How to use custom messages by language 162 | To make it work the messages in the correct language, simply declare the attribute lang in HTML tag 163 | ```html 164 | 165 | ``` 166 | 167 | ## Current version stable 168 | **V1.0.5** 169 | 170 | ## ChangeLog 171 | 172 | **V1.0.5** 173 | - Change format data attribute custom message 174 | 175 | **V1.0.4** 176 | - Correction alert tooltip 177 | 178 | ## Contributing 179 | - Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found. 180 | - Fork repository, make changes, add your name and link in the authors session readme.md 181 | - Send a pull request 182 | 183 | If you want a faster communication, find me on [@ktquez](https://twitter.com/ktquez) 184 | 185 | **thank you** 186 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inspect-form", 3 | "description": "Form validations in Javascript Vanilla, without dependencies and multiple languages", 4 | "version" : "1.0.5", 5 | "main": "./dist/inspect.min.js", 6 | "authors": [ 7 | "Alan Albuquerque (Ktquez) " 8 | ], 9 | "license": [ 10 | "MIT", 11 | "GPL" 12 | ], 13 | "keywords": [ 14 | "form", 15 | "validation", 16 | "inspect" 17 | ], 18 | "ignore" : [ 19 | "node_modules", 20 | "index.html", 21 | "script.js" 22 | ], 23 | "moduleType": [], 24 | "homepage": "https://github.com/ktquez/Inspect", 25 | "ignore" : [ 26 | "node_modules" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /dev/inspect.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Inspect - Form validations in Javascript Vanilla without dependencies and multilanguage 3 | * Copyright (c) 2016 Ktquez 4 | * Project repository: https://github.com/ktquez/Inspect 5 | * Dual licensed under the MIT and GPL licenses. 6 | */ 7 | 8 | (function(window){ 9 | 10 | 'use strict'; 11 | 12 | var Inspect = function(obj){ 13 | 14 | this.config = {}; 15 | 16 | // Checks that the user entered a string with the name of the form 17 | if(typeof obj === 'string'){ 18 | this.config.form = obj; 19 | this.config = this.createConfig(this.config); 20 | this.setForm(obj); 21 | return; 22 | } 23 | 24 | // If sent an object with more settings, merges with the default settings 25 | if (!!obj) this.config = this.createConfig(obj); 26 | 27 | // Initializes the tracking form 28 | this.setForm(this.config.form); 29 | 30 | /** 31 | * Load the language for messages 32 | * Compatibility Ajax 33 | */ 34 | function getXHR(){ 35 | // Demais browsers 36 | if(window.XMLHttpRequest){ 37 | return new XMLHttpRequest(); 38 | } 39 | // Microsoft 40 | try { 41 | return new ActiveXObject("Msxml2.XMLHTTP"); 42 | } 43 | catch (e) { 44 | try { 45 | return new ActiveXObject("Microsoft.XMLHTTP"); 46 | } 47 | catch (e) {} 48 | } 49 | } 50 | 51 | /** 52 | * Ajax 53 | */ 54 | var languague = document.getElementsByTagName('html')[0].getAttribute('lang').toLowerCase(), 55 | xhr = getXHR(); 56 | 57 | xhr.onreadystatechange = function(){ 58 | if(xhr.readyState === 4){ 59 | if(xhr.status === 200){ 60 | Inspect.prototype.messages = JSON.parse(xhr.responseText); 61 | } 62 | } 63 | }; 64 | 65 | var basepath = this.config.basepath; 66 | if (basepath == null) { 67 | basepath = ''; 68 | } 69 | 70 | xhr.open('GET', basepath+'/lang-inspect/'+languague+'.json', true); 71 | xhr.send(); 72 | }; 73 | 74 | // Add to the window object 75 | window.Inspect = Inspect; 76 | 77 | Inspect.prototype = { 78 | 79 | /** 80 | * Prototype to create the instance inspect settings 81 | * @type {Object} 82 | */ 83 | defaults : { 84 | animateScroll : 8, 85 | touched : false, 86 | tooltip : false, 87 | basepath: null 88 | }, 89 | 90 | /** 91 | * instanceOfInpect.make().then(function(data){ 92 | * // código aqui 93 | * }); 94 | * 95 | * make: (AJAX) Validates the form and return the data in a callback 96 | * @return {callback} 97 | */ 98 | make : function(callback){ 99 | var self = this, 100 | objForm = self[self.config.form]; 101 | 102 | objForm.dom.addEventListener('submit', function(e){ 103 | objForm.submitted = true; 104 | self.utils.blockForm(e); 105 | 106 | var data = {}, 107 | errors = [], 108 | arrFields; 109 | 110 | arrFields = [].slice.call(objForm.dom); 111 | arrFields.map(function(field, key){ 112 | errors.push(self.validate(objForm[field.name])); 113 | if (field.type === 'submit') return; 114 | data[field.name] = field.value; 115 | }); 116 | 117 | if (!!errors) self.filter(errors); 118 | 119 | if (!self.fails()) { 120 | callback(data); 121 | objForm.submitted = false; 122 | return; 123 | } 124 | 125 | }, false); 126 | }, 127 | 128 | /** 129 | * instanceOfInpect.toSubmit(); 130 | * 131 | * toSubmit: Submit the form if no error occurs 132 | */ 133 | toSubmit : function(){ 134 | var self = this, 135 | objForm = self[self.config.form]; 136 | 137 | objForm.dom.addEventListener('submit', function(e){ 138 | objForm.submitted = true; 139 | 140 | // for each to Validate form fields 141 | self.utils.convertObjToArray(objForm.dom).map(function(field){ 142 | var error = self.validate(objForm[field.name]); 143 | if (!!error) self.filter(error); 144 | }); 145 | 146 | // If fails, block form and show errors 147 | if (self.fails()) { 148 | self.utils.blockForm(e); 149 | objForm.submitted = false; 150 | } 151 | 152 | }, false); 153 | }, 154 | 155 | /** 156 | * File configuration specifies of the instance of Inspect, for multiple forms in single page 157 | * @param {object} options = Information passed by the user 158 | * @return {object} 159 | */ 160 | createConfig : function(options){ 161 | var self = this; 162 | 163 | var config = JSON.parse(JSON.stringify(self.defaults)); 164 | for(var option in options){ 165 | if(options.hasOwnProperty(option)){ 166 | config[option] = options[option]; 167 | } 168 | } 169 | return config; 170 | 171 | }, 172 | 173 | /** 174 | * setForm: Configure and monitor the set form object 175 | * @param {string} nameForm = name the form 176 | */ 177 | setForm : function(nameForm){ 178 | var self = this; 179 | 180 | self[nameForm] = { 181 | 'submitted' : false, 182 | 'error' : false 183 | }; 184 | 185 | self.prepare(nameForm); 186 | return; 187 | }, 188 | 189 | /** 190 | * Prepare form to validations 191 | * @param {string} nameForm = name the form 192 | */ 193 | prepare : function(nameForm){ 194 | var self = this, 195 | form = document.querySelector('form[name='+nameForm+']'); 196 | 197 | // cache dom 198 | self[nameForm].dom = form; 199 | 200 | // Slice the form in objects with information the fields 201 | self.utils.convertObjToArray(form).map(function(value){ 202 | // Create object specific field the form 203 | self[nameForm][value.name] = { 204 | 'name' : value.name, 205 | 'touched' : false, 206 | 'errors' : [], 207 | 'rules' : self.prepareRules(value.getAttribute('data-rules')), 208 | 'custom' : value.getAttribute('data-msg-custom'), 209 | 'field' : value 210 | }; 211 | 212 | if(self.config.touched) self.touched(self[nameForm][value.name]); 213 | }); 214 | }, 215 | 216 | /** 217 | * Slice rules to validation 218 | * @param {string} rules = Rules informed the attribute [data-rules] 219 | * @return {Array} = Specifics rules of the object 220 | */ 221 | prepareRules : function(rules){ 222 | if (!rules) return false; 223 | return rules.split('|'); 224 | }, 225 | 226 | /** 227 | * Register event listeners, if touched enable 228 | * @param {obj} obj = Object manager with information on field specific of the form 229 | */ 230 | touched : function(obj){ 231 | var self = this; 232 | obj.field.addEventListener('focus', function(){ 233 | obj.touched = true; 234 | }, false); 235 | obj.field.addEventListener('blur', function(e){ 236 | if(!obj.rules.length) return; 237 | 238 | self.untouched(obj); 239 | }, false); 240 | }, 241 | 242 | /** 243 | * Validation on blur field 244 | * @param {object} obj Object manager with information on field specific of the form 245 | */ 246 | untouched : function(obj){ 247 | var self = this; 248 | 249 | obj.touched = false; 250 | 251 | var errors = self.validate(obj); 252 | self.filter(errors); 253 | }, 254 | 255 | /** 256 | * Reset form 257 | */ 258 | pristine : function(){ 259 | var self = this; 260 | self[self.config.form].dom.reset(); 261 | }, 262 | 263 | /** 264 | * Validate rules 265 | * @param {object} obj = Object manager with information on field specific of the form 266 | */ 267 | validate : function(obj){ 268 | var self = this, 269 | rule, 270 | verify; 271 | 272 | // If not exists rules to validation 273 | if (!obj.rules) return false; 274 | 275 | var validation = obj.rules.map(function(value, key){ 276 | if (value.indexOf(':') !== -1) { 277 | rule = value.split(':'); 278 | 279 | // Verify custom rules with others parameters 280 | verify = self.verify[rule[0]](obj.field.value, rule[1]); 281 | }else{ 282 | rule = value; 283 | var val = obj.field.value; 284 | 285 | // Setting for checkbox inputs 286 | if (/(checkbox|radio)/.test(obj.field.type)) { 287 | 288 | if (obj.field.type !== 'radio') { 289 | val = !obj.field.checked ? '' : val; 290 | }else{ 291 | 292 | // Several radios with the same names 293 | var radios = self[self.config.form].dom.querySelectorAll('input[name="'+obj.field.name+'"]'); 294 | var verifyMultipleRadios = self.utils.convertObjToArray(radios).filter(function(value){ 295 | return !!value.checked; 296 | }); 297 | val = !verifyMultipleRadios.length ? '' : val; 298 | } 299 | } 300 | 301 | // Verify normal rules 302 | verify = self.verify[value](val); 303 | } 304 | 305 | // remove error to object 306 | if (obj.errors.indexOf(value) !== -1){ 307 | obj.errors.splice(obj.errors.indexOf(value), 1); 308 | } 309 | 310 | // if error, add error to object 311 | if (verify) obj.errors.push(value); 312 | 313 | // Se não passar na validação, exibe a mensagem de erro 314 | if (verify) self.prepareAlertError(obj, rule); 315 | 316 | return verify; 317 | }); 318 | 319 | // Array with results of the verify rules 320 | return validation; 321 | 322 | }, 323 | 324 | filter : function(errors){ 325 | var self = this; 326 | 327 | // return string with results of validation 328 | var strError = errors.filter(function(value){ 329 | return !!value; 330 | }).toString(); 331 | 332 | // if there are errors (true), sets that there is error in form 333 | if (strError.indexOf('true') !== -1) { 334 | self[self.config.form].error = true; 335 | 336 | // Se existir error, move o scroll para o alert de cima para baixo 337 | if (self[self.config.form].error) { 338 | self.utils.animateScroll(self); 339 | } 340 | 341 | return; 342 | } 343 | 344 | // If no errors returns false 345 | self[self.config.form].error = false; 346 | 347 | }, 348 | 349 | /** 350 | * Notify if there is any failure in the form 351 | * @return {boolean} 352 | */ 353 | fails : function(){ 354 | var self = this; 355 | return self[self.config.form].error; 356 | }, 357 | 358 | /** 359 | * Handle to create the message element 360 | * @param {Object} obj = Object manager with information on field specific of the form 361 | * @param {string} rule = Rule that the error occurred 362 | */ 363 | prepareAlertError : function(obj, rule){ 364 | var self = this, 365 | block = obj.field.parentElement, 366 | alert = self.managerAlertError(obj, block); 367 | 368 | // If alert exists 369 | if (!alert) return; 370 | 371 | // Feeds the alert with the error message 372 | self.utils.setMessageError(obj, alert.querySelector('.inspect-message-text'), rule); 373 | 374 | // Feeds the block 375 | block.style.position = 'relative'; 376 | var prevBlock = block.previousElementSibling; 377 | var nextBlock = block.nextElementSibling; 378 | 379 | // Z-index 380 | if (!!prevBlock) { 381 | block.style.zIndex = !prevBlock.style.zIndex.length ? (!nextBlock.style.zIndex.length ? '900' : Number(nextBlock.style.zIndex) + 2) : prevBlock.style.zIndex; 382 | block.style.zIndex = block.style.zIndex - 1; 383 | } else { 384 | block.style.zIndex = '1000'; 385 | } 386 | 387 | block.appendChild(alert); 388 | }, 389 | 390 | /** 391 | * Manages the creation of error alerts 392 | */ 393 | managerAlertError : function(obj, block){ 394 | var self = this; 395 | 396 | if (block.querySelector('.inspect-message')) return false; 397 | 398 | if (self.config.tooltip) { 399 | return self.utils.createTooltipAlert(obj); 400 | } 401 | return self.utils.createSimpleAlert(obj); 402 | }, 403 | }; 404 | 405 | Inspect.prototype.utils = { 406 | 407 | animateScroll : function(data){ 408 | 409 | var el = data[data.config.form].dom.querySelector('.inspect-message').parentElement, 410 | offset = el.getBoundingClientRect(), 411 | doc = el.ownerDocument, 412 | win = doc.defaultView, 413 | docEl = doc.documentElement, 414 | pos = offset.top + win.pageYOffset - docEl.clientTop; 415 | 416 | 417 | // Runs the scroll at intervals 418 | var animate = setInterval(function(){ 419 | scroll(data.config.animateScroll); 420 | }, 10); 421 | 422 | function scroll(interval){ 423 | var scroll = window.scrollY; 424 | 425 | if (pos < scroll){ 426 | window.scrollTo(0, scroll - interval); 427 | return; 428 | } 429 | 430 | resetScroll(); 431 | return; 432 | } 433 | 434 | // Remove the iteration range 435 | function resetScroll(){ 436 | clearInterval(animate); 437 | return; 438 | } 439 | }, 440 | 441 | /** 442 | * Create a simple alert with the message text, for the user to customize 443 | */ 444 | createSimpleAlert : function(obj){ 445 | 446 | var div = document.createElement('div'), 447 | main = document.createElement('span'); 448 | 449 | div.setAttribute('style', 'position:relative;width:100%;float:left;'); 450 | div.setAttribute('class','inspect-message'); 451 | 452 | main.style.color = 'red'; 453 | main.setAttribute('class','inspect-message-text'); 454 | 455 | obj.field.addEventListener('focus', function(e){ 456 | e.preventDefault(); 457 | e.stopPropagation(); 458 | 459 | if(!div.parentElement) return; 460 | div.parentElement.removeChild(div); 461 | 462 | }); 463 | 464 | div.appendChild(main); 465 | return div; 466 | }, 467 | 468 | /** 469 | * Create alert tooltip 470 | */ 471 | createTooltipAlert : function(obj){ 472 | 473 | var div = document.createElement('div'), 474 | main = document.createElement('span'), 475 | bottom = document.createElement('span'), 476 | arrow = document.createElement('span'), 477 | close = document.createElement('span'), 478 | field = obj.field; 479 | 480 | div.setAttribute('style', 'position:absolute;z-index:10;opacity:0;visibility:hidden;left:-100px;top:'+ Number((field.clientHeight + field.offsetTop) + 10) +'px;box-shadow:0 0 10px #aaa;transition:all 0.5s'); 481 | div.setAttribute('class','inspect-message'); 482 | 483 | arrow.setAttribute('style', 'border-style:solid;border-width:6px;border-color:transparent;border-bottom-color:rgba(231,76,60,0.6);position:absolute;left:50%;transform:translateX(-50%);top:-12px;'); 484 | 485 | close.setAttribute('style', 'font-weight:bold;position:absolute;right:3px;bottom:-2px;color:#999;cursor:pointer;padding:0 3px 0'); 486 | close.setAttribute('class','close-inspect-message'); 487 | close.innerHTML = "×"; 488 | 489 | bottom.setAttribute('style', 'background:#f2f2f2;height:15px;width:100%;float:left;'); 490 | 491 | main.setAttribute('style', 'background:rgba(231,76,60,0.8);font-size:14px;font-family:inherit;line-height:1em;color:#fff;width:160px;padding:10px 6px;text-align:center;float:left;'); 492 | main.setAttribute('class','inspect-message-text'); 493 | 494 | div.appendChild(main); 495 | div.appendChild(bottom); 496 | bottom.appendChild(arrow); 497 | div.appendChild(close); 498 | 499 | /** 500 | * Listeners 501 | */ 502 | close.addEventListener('click', function(e){ 503 | e.preventDefault(); 504 | e.stopPropagation(); 505 | 506 | // Animating the div to hide 507 | div.style.left = '-100px'; 508 | div.style.visibility = 'hidden'; 509 | div.style.opacity = '0'; 510 | setTimeout(function(){ 511 | div.parentElement.removeChild(div); 512 | }, 500); 513 | 514 | }, false); 515 | 516 | obj.field.addEventListener('focus', function(e){ 517 | e.preventDefault(); 518 | e.stopPropagation(); 519 | 520 | // Animating the div to hide 521 | div.style.left = '-100px'; 522 | div.style.visibility = 'hidden'; 523 | div.style.opacity = '0'; 524 | setTimeout(function(){ 525 | if(!div.parentElement) return; 526 | div.parentElement.removeChild(div); 527 | }, 500); 528 | 529 | }); 530 | 531 | // Animating the div to display 532 | setTimeout(function(){ 533 | if (/(checkbox|radio)/.test(field.type)) { 534 | div.style.left = field.offsetLeft + parseInt(field.offsetWidth / 2) - 86 + 'px'; 535 | }else{ 536 | div.style.left = (field.offsetWidth - 174) + 'px'; 537 | } 538 | div.style.visibility = 'visible'; 539 | div.style.opacity = '1'; 540 | }, 200); 541 | 542 | return div; 543 | }, 544 | 545 | /** 546 | * Assigns a custom error message alert 547 | * @param {Object} obj = Object manager with information on field specific of the form 548 | * @param {Object} elemText = Element that the message text is displayed 549 | * @param {String} rule = Rule that the error occurred 550 | */ 551 | setMessageError : function(obj, elemText, rule){ 552 | var self = this, 553 | custom = !!obj.custom ? obj.custom : obj.name, 554 | messages = Inspect.prototype.messages, 555 | msgRule; 556 | 557 | if (Array.isArray(rule)) { 558 | msgRule = messages[rule[0]]; 559 | msgRule = msgRule.replace(':other', rule[1]); 560 | }else{ 561 | msgRule = messages[rule]; 562 | } 563 | 564 | msgRule = msgRule.replace(/(:custom)/g, custom); 565 | elemText.innerHTML = msgRule; 566 | return; 567 | }, 568 | 569 | convertObjToArray : function(obj){ 570 | return [].slice.call(obj); 571 | }, 572 | 573 | blockForm : function(event){ 574 | event.preventDefault(); 575 | } 576 | }; 577 | 578 | Inspect.prototype.messages = { 579 | "required" : "The field :custom is required", 580 | "email" : "Please, type a valid :custom", 581 | "max" : "The :custom field must contain a maximum of :other characters", 582 | "min" : "The :custom field must contain a minimum of :other characters", 583 | "card" : "Enter the :custom correctly", 584 | "cpf" : "The :custom typed is invalid", 585 | "cnpj" : "The :custom typed is invalid", 586 | "cpfCnpj" : "The :custom is invalid, please try again", 587 | "cep" : "The :custom typed is invalid", 588 | "number" : "The field :custom must be a number", 589 | "url" : "Please enter a valid :custom" 590 | }; 591 | 592 | /** 593 | * Returns true if it does not pass verification, returns false if pass the validation 594 | * @return boolean 595 | */ 596 | Inspect.prototype.verify = { 597 | 598 | required : function(value){ 599 | return !value ? true : false; 600 | }, 601 | 602 | email : function(value) { 603 | return !/[0-9\-\.\_a-z]+@[0-9\-\.a-z]+\.[a-z]+/.test(value) ? true : false; 604 | }, 605 | 606 | max : function(value, max) { 607 | return value.length > max ? true : false; 608 | }, 609 | 610 | min : function(value, min) { 611 | return value.length < min ? true : false; 612 | }, 613 | 614 | cpfCnpj : function(value) { 615 | if (this.cpf(value) && this.cnpj(value)) return true; 616 | return false; 617 | }, 618 | 619 | cnpj : function(value) { 620 | var cnpj = value.replace(/(\.|\-|\/)/g, ''), 621 | numbers = [].slice.call(cnpj), 622 | sizeFirstOp = 5, 623 | sizeSecondOp = 6, 624 | firstResult = 0, 625 | secondResult = 0, 626 | i; 627 | 628 | /** 629 | * Se não conter a quantidade correta 630 | */ 631 | if (numbers.length != 14) return true; 632 | 633 | /** 634 | * Prepara a verificação do primeiro dígito 635 | */ 636 | for (i=0;i<12;i++) { 637 | firstResult += (parseInt(numbers[i]) * parseInt(sizeFirstOp)); 638 | if (sizeFirstOp === 2) { 639 | sizeFirstOp = 9; 640 | continue; 641 | } 642 | --sizeFirstOp; 643 | } 644 | 645 | firstResult = (firstResult * 10) % 11; 646 | 647 | // Caso o resto seja 10, o dígito será sempre 0 648 | firstResult = firstResult === 10 ? 0 : firstResult; 649 | 650 | // Se o resultado não coincidir com o 1 dígito verificador 651 | if (firstResult !== Number(numbers[12])) return true; 652 | 653 | /** 654 | * Prepara a verificação do segundo dígito 655 | */ 656 | for (i=0;i<13;i++) { 657 | secondResult += (parseInt(numbers[i]) * parseInt(sizeSecondOp)); 658 | if (sizeSecondOp === 2) { 659 | sizeSecondOp = 9; 660 | continue; 661 | } 662 | --sizeSecondOp; 663 | } 664 | 665 | secondResult = (secondResult * 10) % 11; 666 | 667 | // Caso o resto seja 10, o dígito será sempre 0 668 | secondResult = secondResult === 10 ? 0 : secondResult; 669 | 670 | // Se o resultado não coincidir com o 1 dígito verificador 671 | if (secondResult !== Number(numbers[13])) return true; 672 | 673 | 674 | // Tudo ok, sem erros 675 | return false; 676 | }, 677 | 678 | cpf : function(value){ 679 | var cpf = value.replace(/(\.|\-)/g, ''), 680 | numbers = [].slice.call(cpf), 681 | sizeFirstOp = 10, 682 | sizeSecondOp = 11, 683 | firstResult = 0, 684 | secondResult = 0, 685 | irregular, 686 | i; 687 | 688 | /** 689 | * Se não conter a quantidade correta 690 | */ 691 | if (numbers.length != 11) return true; 692 | 693 | /** 694 | * São irregulares todos os CPFs que os dígitos sejam iguais (por exemplo: 11111111111) 695 | */ 696 | irregular = numbers.every(function(value){ 697 | return value === numbers[0]; 698 | }); 699 | 700 | if (irregular) return true; 701 | 702 | for (i=0;i<9;i++) { 703 | firstResult += (parseInt(numbers[i]) * parseInt(sizeFirstOp)); 704 | --sizeFirstOp; 705 | } 706 | firstResult = (firstResult * 10) % 11; 707 | 708 | // Caso o resto seja 10, o dígito será sempre 0 709 | firstResult = firstResult === 10 ? 0 : firstResult; 710 | 711 | // Se o resultado não coincidir com o 1 dígito verificador 712 | if (firstResult !== Number(numbers[9])) return true; 713 | 714 | /** 715 | * Prepara a verificação do segundo dígito 716 | */ 717 | for (i=0;i<10;i++) { 718 | secondResult += (parseInt(numbers[i]) * parseInt(sizeSecondOp)); 719 | --sizeSecondOp; 720 | } 721 | secondResult = (secondResult * 10) % 11; 722 | 723 | // Caso o resto seja 10, o dígito será sempre 0 724 | secondResult = secondResult === 10 ? 0 : secondResult; 725 | 726 | // Se o resultado não coincidir com o 2 dígito verificador 727 | if (secondResult !== Number(numbers[10])) return true; 728 | 729 | // Tudo ok, sem erros 730 | return false; 731 | }, 732 | 733 | cep : function(value) { 734 | return !/(^[0-9]{5}-[0-9]{3}$|^[0-9]{8}$)/.test(value) ? true : false; 735 | }, 736 | 737 | card : function(value) { 738 | var card = value.replace(/(\s|\-|\.)/g, ''); 739 | return !/(^[0-9]{16}$)/.test(card) ? true : false; 740 | }, 741 | 742 | number : function(value) { 743 | return !Number(value); 744 | }, 745 | 746 | url : function(value) { 747 | return !/(http|https)+(:\/\/)+(www.|)+[0-9a-z\-]+\.(.)+/.test(value); 748 | } 749 | }; 750 | // End of Inspect 751 | 752 | })(window); 753 | 754 | if (typeof module !== 'undefined' && module.exports) { 755 | module.exports = Inspect; 756 | } -------------------------------------------------------------------------------- /dev/lang-inspect/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "The field :custom is required", 3 | "email" : "Please, type a valid :custom", 4 | "max" : "The :custom field must contain a maximum of :other characters", 5 | "min" : "The :custom field must contain a minimum of :other characters", 6 | "card" : "Enter the :custom correctly", 7 | "cpf" : "The :custom typed is invalid", 8 | "cnpj" : "The :custom typed is invalid", 9 | "cpfCnpj" : "The :custom is invalid, please try again", 10 | "cep" : "The :custom typed is invalid", 11 | "number" : "The field :custom must be a number", 12 | "url" : "Please enter a valid :custom" 13 | } -------------------------------------------------------------------------------- /dev/lang-inspect/es.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "Se requiere el campo :custom", 3 | "email" : "Se requiere una dirección de :custom válida.", 4 | "max" : "El campo :custom debe contener un máximo de :other caracteres", 5 | "min" : "El campo :custom debe contener al menos :other caracteres", 6 | "card" : "Escriba el :custom correctamente", 7 | "cpf" : "El :custom introducido no es válido.", 8 | "cnpj" : "El :custom introducido no es válido.", 9 | "cpfCnpj" : "El :custom no es válido, por favor, inténtelo de nuevo", 10 | "cep" : "El :custom introducido no es válido.", 11 | "number" : "EL Campo :custom Debe ser un número", 12 | "url" : "Por favor, introduzca una :custom válido" 13 | } -------------------------------------------------------------------------------- /dev/lang-inspect/pt-br.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "O Campo :custom é obrigatório", 3 | "email" : "Por favor, digite um :custom válido", 4 | "max" : "O campo :custom tem que conter no máximo :other caracteres", 5 | "min" : "O campo :custom tem que conter no mínimo :other caracteres", 6 | "card" : "Digite o :custom corretamente", 7 | "cpf" : "O :custom digitado é inválido", 8 | "cnpj" : "O :custom digitado é inválido", 9 | "cpfCnpj" : "O :custom é inválido, por favor tente novamente", 10 | "cep" : "O :custom digitado é inválido", 11 | "number" : "O Campo :custom tem que ser um número", 12 | "url" : "Por favor, digite uma :custom válida" 13 | } -------------------------------------------------------------------------------- /dev/lang-inspect/pt.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "O Campo :custom é obrigatório", 3 | "email" : "Por favor, digite um :custom válido", 4 | "max" : "O campo :custom tem que conter no máximo :other caracteres", 5 | "min" : "O campo :custom tem que conter no mínimo :other caracteres", 6 | "card" : "Digite o :custom corretamente", 7 | "cpf" : "O :custom digitado é inválido", 8 | "cnpj" : "O :custom digitado é inválido", 9 | "cpfCnpj" : "O :custom é inválido, por favor tente novamente", 10 | "cep" : "O :custom digitado é inválido", 11 | "number" : "O Campo :custom tem que ser um número", 12 | "url" : "Por favor, digite uma :custom válida" 13 | } -------------------------------------------------------------------------------- /dist/inspect.min.js: -------------------------------------------------------------------------------- 1 | !function(e){"use strict";function t(){if(e.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}}function r(){var e=document.getElementsByTagName("script"),t=e[e.length-1];if(t.getAttribute.length){var r=t.getAttribute("src").split("/");return r.splice(r.length-1,1),r=r.toString().replace(/(,)/g,"/")}}var n=function(e){return this.config={},"string"==typeof e?(this.config.form=e,this.config=this.createConfig(this.config),void this.setForm(e)):(e&&(this.config=this.createConfig(e)),void this.setForm(this.config.form))};e.Inspect=n,n.prototype={defaults:{animateScroll:8,touched:!1,tooltip:!1},make:function(e){var t=this,r=t[t.config.form];r.dom.addEventListener("submit",function(n){r.submitted=!0,t.utils.blockForm(n);var i,o={},s=[];return i=[].slice.call(r.dom),i.map(function(e,n){s.push(t.validate(r[e.name])),"submit"!==e.type&&(o[e.name]=e.value)}),s&&t.filter(s),t.fails()?void 0:(e(o),void(r.submitted=!1))},!1)},toSubmit:function(){var e=this,t=e[e.config.form];t.dom.addEventListener("submit",function(r){t.submitted=!0,e.utils.convertObjToArray(t.dom).map(function(r){var n=e.validate(t[r.name]);n&&e.filter(n)}),e.fails()&&(e.utils.blockForm(r),t.submitted=!1)},!1)},createConfig:function(e){var t=this,r=JSON.parse(JSON.stringify(t.defaults));for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return r},setForm:function(e){var t=this;t[e]={submitted:!1,error:!1},t.prepare(e)},prepare:function(e){var t=this,r=document.querySelector("form[name="+e+"]");t[e].dom=r,t.utils.convertObjToArray(r).map(function(r){t[e][r.name]={name:r.name,touched:!1,errors:[],rules:t.prepareRules(r.getAttribute("data-rules")),custom:r.getAttribute("data-msg-custom"),field:r},t.config.touched&&t.touched(t[e][r.name])})},prepareRules:function(e){return e?e.split("|"):!1},touched:function(e){var t=this;e.field.addEventListener("focus",function(){e.touched=!0},!1),e.field.addEventListener("blur",function(r){e.rules.length&&t.untouched(e)},!1)},untouched:function(e){var t=this;e.touched=!1;var r=t.validate(e);t.filter(r)},pristine:function(){var e=this;e[e.config.form].dom.reset()},validate:function(e){var t,r,n=this;if(!e.rules)return!1;var i=e.rules.map(function(i,o){if(-1!==i.indexOf(":"))t=i.split(":"),r=n.verify[t[0]](e.field.value,t[1]);else{t=i;var s=e.field.value;if(/(checkbox|radio)/.test(e.field.type))if("radio"!==e.field.type)s=e.field.checked?s:"";else{var a=n[n.config.form].dom.querySelectorAll('input[name="'+e.field.name+'"]'),l=n.utils.convertObjToArray(a).filter(function(e){return!!e.checked});s=l.length?s:""}r=n.verify[i](s)}return-1!==e.errors.indexOf(i)&&e.errors.splice(e.errors.indexOf(i),1),r&&e.errors.push(i),r&&n.prepareAlertError(e,t),r});return i},filter:function(e){var t=this,r=e.filter(function(e){return!!e}).toString();return-1!==r.indexOf("true")?(t[t.config.form].error=!0,void(t[t.config.form].error&&t.utils.animateScroll(t))):void(t[t.config.form].error=!1)},fails:function(){var e=this;return e[e.config.form].error},prepareAlertError:function(e,t){var r=this,n=e.field.parentElement,i=r.managerAlertError(e,n);if(i){r.utils.setMessageError(e,i.querySelector(".inspect-message-text"),t),n.style.position="relative";var o=n.previousElementSibling,s=n.nextElementSibling;o?(n.style.zIndex=o.style.zIndex.length?o.style.zIndex:s.style.zIndex.length?Number(s.style.zIndex)+2:"900",n.style.zIndex=n.style.zIndex-1):n.style.zIndex="1000",n.appendChild(i)}},managerAlertError:function(e,t){var r=this;return t.querySelector(".inspect-message")?!1:r.config.tooltip?r.utils.createTooltipAlert(e):r.utils.createSimpleAlert(e)}},n.prototype.utils={animateScroll:function(t){function r(t){var r=e.scrollY;return r>c?void e.scrollTo(0,r-t):void n()}function n(){clearInterval(u)}var i=t[t.config.form].dom.querySelector(".inspect-message").parentElement,o=i.getBoundingClientRect(),s=i.ownerDocument,a=s.defaultView,l=s.documentElement,c=o.top+a.pageYOffset-l.clientTop,u=setInterval(function(){r(t.config.animateScroll)},10)},createSimpleAlert:function(e){var t=document.createElement("div"),r=document.createElement("span");return t.setAttribute("style","position:relative;width:100%;float:left;"),t.setAttribute("class","inspect-message"),r.style.color="red",r.setAttribute("class","inspect-message-text"),e.field.addEventListener("focus",function(e){e.preventDefault(),e.stopPropagation(),t.parentElement&&t.parentElement.removeChild(t)}),t.appendChild(r),t},createTooltipAlert:function(e){var t=document.createElement("div"),r=document.createElement("span"),n=document.createElement("span"),i=document.createElement("span"),o=document.createElement("span"),s=e.field;return t.setAttribute("style","position:absolute;z-index:10;opacity:0;visibility:hidden;left:-100px;top:"+Number(s.clientHeight+s.offsetTop+10)+"px;box-shadow:0 0 10px #aaa;transition:all 0.5s"),t.setAttribute("class","inspect-message"),i.setAttribute("style","border-style:solid;border-width:6px;border-color:transparent;border-bottom-color:rgba(231,76,60,0.6);position:absolute;left:50%;transform:translateX(-50%);top:-12px;"),o.setAttribute("style","font-weight:bold;position:absolute;right:3px;bottom:-2px;color:#999;cursor:pointer;padding:0 3px 0"),o.setAttribute("class","close-inspect-message"),o.innerHTML="×",n.setAttribute("style","background:#f2f2f2;height:15px;width:100%;float:left;"),r.setAttribute("style","background:rgba(231,76,60,0.8);font-size:14px;font-family:inherit;line-height:1em;color:#fff;width:160px;padding:10px 6px;text-align:center;float:left;"),r.setAttribute("class","inspect-message-text"),t.appendChild(r),t.appendChild(n),n.appendChild(i),t.appendChild(o),o.addEventListener("click",function(e){e.preventDefault(),e.stopPropagation(),t.style.left="-100px",t.style.visibility="hidden",t.style.opacity="0",setTimeout(function(){t.parentElement.removeChild(t)},500)},!1),e.field.addEventListener("focus",function(e){e.preventDefault(),e.stopPropagation(),t.style.left="-100px",t.style.visibility="hidden",t.style.opacity="0",setTimeout(function(){t.parentElement&&t.parentElement.removeChild(t)},500)}),setTimeout(function(){/(checkbox|radio)/.test(s.type)?t.style.left=s.offsetLeft+parseInt(s.offsetWidth/2)-86+"px":t.style.left=s.offsetWidth-174+"px",t.style.visibility="visible",t.style.opacity="1"},200),t},setMessageError:function(e,t,r){var i,o=e.custom?e.custom:e.name,s=n.prototype.messages;Array.isArray(r)?(i=s[r[0]],i=i.replace(":other",r[1])):i=s[r],i=i.replace(/(:custom)/g,o),t.innerHTML=i},convertObjToArray:function(e){return[].slice.call(e)},blockForm:function(e){e.preventDefault()}},n.prototype.messages={required:"The field :custom is required",email:"Please, type a valid :custom",max:"The :custom field must contain a maximum of :other characters",min:"The :custom field must contain a minimum of :other characters",card:"Enter the :custom correctly",cpf:"The :custom typed is invalid",cnpj:"The :custom typed is invalid",cpfCnpj:"The :custom is invalid, please try again",cep:"The :custom typed is invalid",number:"The field :custom must be a number",url:"Please enter a valid :custom"},n.prototype.verify={required:function(e){return!e},email:function(e){return!/[0-9\-\.\_a-z]+@[0-9\-\.a-z]+\.[a-z]+/.test(e)},max:function(e,t){return e.length>t},min:function(e,t){return e.lengtht;t++)s+=parseInt(n[t])*parseInt(i),2!==i?--i:i=9;if(s=10*s%11,s=10===s?0:s,s!==Number(n[12]))return!0;for(t=0;13>t;t++)a+=parseInt(n[t])*parseInt(o),2!==o?--o:o=9;return a=10*a%11,a=10===a?0:a,a!==Number(n[13])},cpf:function(e){var t,r,n=e.replace(/(\.|\-)/g,""),i=[].slice.call(n),o=10,s=11,a=0,l=0;if(11!=i.length)return!0;if(t=i.every(function(e){return e===i[0]}))return!0;for(r=0;9>r;r++)a+=parseInt(i[r])*parseInt(o),--o;if(a=10*a%11,a=10===a?0:a,a!==Number(i[9]))return!0;for(r=0;10>r;r++)l+=parseInt(i[r])*parseInt(s),--s;return l=10*l%11,l=10===l?0:l,l!==Number(i[10])},cep:function(e){return!/(^[0-9]{5}-[0-9]{3}$|^[0-9]{8}$)/.test(e)},card:function(e){var t=e.replace(/(\s|\-|\.)/g,"");return!/(^[0-9]{16}$)/.test(t)},number:function(e){return!Number(e)},url:function(e){return!/(http|https)+(:\/\/)+(www.|)+[0-9a-z\-]+\.(.)+/.test(e)}},function(){var e=document.getElementsByTagName("html")[0].getAttribute("lang").toLowerCase(),i=t();i.onreadystatechange=function(){4===i.readyState&&200===i.status&&(n.prototype.messages=JSON.parse(i.responseText))},i.open("GET",r()+"/lang-inspect/"+e+".json",!0),i.send()}()}(window),"undefined"!=typeof module&&module.exports&&(module.exports=Inspect); -------------------------------------------------------------------------------- /dist/lang-inspect/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "The field :custom is required", 3 | "email" : "Please, type a valid :custom", 4 | "max" : "The :custom field must contain a maximum of :other characters", 5 | "min" : "The :custom field must contain a minimum of :other characters", 6 | "card" : "Enter the :custom correctly", 7 | "cpf" : "The :custom typed is invalid", 8 | "cnpj" : "The :custom typed is invalid", 9 | "cpfCnpj" : "The :custom is invalid, please try again", 10 | "cep" : "The :custom typed is invalid", 11 | "number" : "The field :custom must be a number", 12 | "url" : "Please enter a valid :custom" 13 | } -------------------------------------------------------------------------------- /dist/lang-inspect/es.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "Se requiere el campo :custom", 3 | "email" : "Se requiere una dirección de :custom válida.", 4 | "max" : "El campo :custom debe contener un máximo de :other caracteres", 5 | "min" : "El campo :custom debe contener al menos :other caracteres", 6 | "card" : "Escriba el :custom correctamente", 7 | "cpf" : "El :custom introducido no es válido.", 8 | "cnpj" : "El :custom introducido no es válido.", 9 | "cpfCnpj" : "El :custom no es válido, por favor, inténtelo de nuevo", 10 | "cep" : "El :custom introducido no es válido.", 11 | "number" : "EL Campo :custom Debe ser un número", 12 | "url" : "Por favor, introduzca una :custom válido" 13 | } -------------------------------------------------------------------------------- /dist/lang-inspect/pt-br.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "O Campo :custom é obrigatório", 3 | "email" : "Por favor, digite um :custom válido", 4 | "max" : "O campo :custom tem que conter no máximo :other caracteres", 5 | "min" : "O campo :custom tem que conter no mínimo :other caracteres", 6 | "card" : "Digite o :custom corretamente", 7 | "cpf" : "O :custom digitado é inválido", 8 | "cnpj" : "O :custom digitado é inválido", 9 | "cpfCnpj" : "O :custom é inválido, por favor tente novamente", 10 | "cep" : "O :custom digitado é inválido", 11 | "number" : "O Campo :custom tem que ser um número", 12 | "url" : "Por favor, digite uma :custom válida" 13 | } -------------------------------------------------------------------------------- /dist/lang-inspect/pt.json: -------------------------------------------------------------------------------- 1 | { 2 | "required" : "O Campo :custom é obrigatório", 3 | "email" : "Por favor, digite um :custom válido", 4 | "max" : "O campo :custom tem que conter no máximo :other caracteres", 5 | "min" : "O campo :custom tem que conter no mínimo :other caracteres", 6 | "card" : "Digite o :custom corretamente", 7 | "cpf" : "O :custom digitado é inválido", 8 | "cnpj" : "O :custom digitado é inválido", 9 | "cpfCnpj" : "O :custom é inválido, por favor tente novamente", 10 | "cep" : "O :custom digitado é inválido", 11 | "number" : "O Campo :custom tem que ser um número", 12 | "url" : "Por favor, digite uma :custom válida" 13 | } -------------------------------------------------------------------------------- /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ktquez/Inspect/8a24677640395def8fab0de9b9d25b561f258b18/example.gif -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uglify = require('gulp-uglify'); 3 | var jshint = require('gulp-jshint'); 4 | var concat = require('gulp-concat'); 5 | var clean = require('gulp-clean'); 6 | 7 | gulp.task('jshint', function(){ 8 | return gulp.src('./dev/*.js') 9 | .pipe(jshint()) 10 | .pipe(jshint.reporter('default')); 11 | }); 12 | 13 | gulp.task('clean', function(){ 14 | return gulp.src('./dist/inspect.min.js') 15 | .pipe(clean()); 16 | }) 17 | 18 | gulp.task('dist', ['clean'], function(){ 19 | return gulp.src('./dev/*.js') 20 | .pipe(uglify()) 21 | .pipe(concat('inspect.min.js')) 22 | .pipe(gulp.dest('./dist/')); 23 | }); 24 | 25 | gulp.task('default', ['jshint', 'dist']); -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Demo - Inspect - Form Validation 7 | 8 | 36 | 37 | 38 | 39 | 40 |
41 | 46 | 51 | 56 | 61 | 66 | 71 | 76 | 87 | 92 |

93 | SEXO: 94 |

95 | 98 | 101 | 104 | 109 | 112 |
113 | 114 |
115 | 120 | 123 |
124 | 125 | 126 | 127 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /license-gpl-v2.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | -------------------------------------------------------------------------------- /license-mit.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | 23 | #### Copyright (c) 2015 Ktquez 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inspect-form", 3 | "author": "Alan Albuquerque (Ktquez) (http://ktquez.com)", 4 | "description": "Form validations in Javascript Vanilla, without dependencies and multiple languages", 5 | "version": "1.0.5", 6 | "main": "./dist/inspect.min.js", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/ktquez/Inspect.git" 10 | }, 11 | "keywords": [ 12 | "form", 13 | "validation", 14 | "inspect" 15 | ], 16 | "license": [ 17 | "MIT", 18 | "GPL" 19 | ], 20 | "bugs": { 21 | "url": "https://github.com/ktquez/Inspect/issues" 22 | }, 23 | "homepage": "https://github.com/ktquez/Inspect#readme", 24 | "devDependencies": { 25 | "gulp": "^3.9.1", 26 | "gulp-clean": "^0.3.2", 27 | "gulp-cli": "^1.2.1", 28 | "gulp-concat": "^2.6.0", 29 | "gulp-jshint": "^2.0.0", 30 | "gulp-uglify": "^1.5.3", 31 | "jshint": "^2.9.1" 32 | } 33 | } 34 | --------------------------------------------------------------------------------