diff --git a/validate.min.js b/validate.min.js new file mode 100644 index 0000000..f78a472 --- /dev/null +++ b/validate.min.js @@ -0,0 +1,8 @@ +/* + * validate.js 1.4.1 + * Copyright (c) 2011 - 2014 Rick Harrison, http://rickharrison.me + * validate.js is open sourced under the MIT license. + * Portions of validate.js are inspired by CodeIgniter. + * http://rickharrison.github.com/validate.js + */ +!function(e,t,a){var n={messages:{required:"The %s field is required.",matches:"The %s field does not match the %s field.","default":"The %s field is still set to default, please change.",valid_email:"The %s field must contain a valid email address.",valid_emails:"The %s field must contain all valid email addresses.",min_length:"The %s field must be at least %s characters in length.",max_length:"The %s field must not exceed %s characters in length.",exact_length:"The %s field must be exactly %s characters in length.",greater_than:"The %s field must contain a number greater than %s.",less_than:"The %s field must contain a number less than %s.",alpha:"The %s field must only contain alphabetical characters.",alpha_numeric:"The %s field must only contain alpha-numeric characters.",alpha_dash:"The %s field must only contain alpha-numeric characters, underscores, and dashes.",numeric:"The %s field must contain only numbers.",integer:"The %s field must contain an integer.",decimal:"The %s field must contain a decimal number.",is_natural:"The %s field must contain only positive numbers.",is_natural_no_zero:"The %s field must contain a number greater than zero.",valid_ip:"The %s field must contain a valid IP.",valid_base64:"The %s field must contain a base64 string.",valid_credit_card:"The %s field must contain a valid credit card number.",is_file_type:"The %s field must contain only %s files.",valid_url:"The %s field must contain a valid URL.",greater_than_date:"The %s field must contain a more recent date than %s.",less_than_date:"The %s field must contain an older date than %s.",greater_than_or_equal_date:"The %s field must contain a date that's at least as recent as %s.",less_than_or_equal_date:"The %s field must contain a date that's %s or older."},callback:function(){}},s=/^(.+?)\[(.+)\]$/,i=/^[0-9]+$/,r=/^\-?[0-9]+$/,l=/^\-?[0-9]*\.?[0-9]+$/,u=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,o=/^[a-z]+$/i,d=/^[a-z0-9]+$/i,h=/^[a-z0-9_\-]+$/i,c=/^[0-9]+$/i,f=/^[1-9][0-9]*$/i,m=/^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$/i,p=/[^a-zA-Z0-9\/\+=]/i,_=/^[\d\-\s]+$/,v=/^((http|https):\/\/(\w+:{0,1}\w*@)?(\S+)|)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/,g=/\d{4}-\d{1,2}-\d{1,2}/,y=function(e,t,s){this.callback=s||n.callback,this.errors=[],this.fields={},this.form=this._formByNameOrNode(e)||{},this.messages={},this.handlers={},this.conditionals={};for(var i=0,r=t.length;r>i;i++){var l=t[i];if((l.name||l.names)&&l.rules)if(l.names)for(var u=0,o=l.names.length;o>u;u++)this._addField(l,l.names[u]);else this._addField(l,l.name)}var d=this.form.onsubmit;this.form.onsubmit=function(e){return function(t){try{return e._validateForm(t)&&(d===a||d())}catch(n){}}}(this)},b=function(e,t){var a;{if(!(e.length>0)||"radio"!==e[0].type&&"checkbox"!==e[0].type)return e[t];for(a=0,elementLength=e.length;a0?s[0].type:s.type,n.value=b(s,"value"),n.checked=b(s,"checked"),n.depends&&"function"==typeof n.depends?n.depends.call(this,n)&&this._validateField(n):n.depends&&"string"==typeof n.depends&&this.conditionals[n.depends]?this.conditionals[n.depends].call(this,n)&&this._validateField(n):this._validateField(n))}return"function"==typeof this.callback&&this.callback(this.errors,e),this.errors.length>0&&(e&&e.preventDefault?e.preventDefault():event&&(event.returnValue=!1)),!0},y.prototype._validateField=function(e){for(var t=e.rules.split("|"),i=e.rules.indexOf("required"),r=!e.value||""===e.value||e.value===a,l=0,u=t.length;u>l;l++){var o=t[l],d=null,h=!1,c=s.exec(o);if((-1!==i||-1!==o.indexOf("!callback_")||!r)&&(c&&(o=c[1],d=c[2]),"!"===o.charAt(0)&&(o=o.substring(1,o.length)),"function"==typeof this._hooks[o]?this._hooks[o].apply(this,[e,d])||(h=!0):"callback_"===o.substring(0,9)&&(o=o.substring(9,o.length),"function"==typeof this.handlers[o]&&this.handlers[o].apply(this,[e.value,d,e])===!1&&(h=!0)),h)){var f=this.messages[e.name+"."+o]||this.messages[o]||n.messages[o],m="An error has occurred with the "+e.display+" field.";f&&(m=f.replace("%s",e.display),d&&(m=m.replace("%s",this.fields[d]?this.fields[d].display:d))),this.errors.push({id:e.id,element:e.element,name:e.name,message:m,rule:o});break}}},y.prototype._getValidDate=function(e){if(!e.match("today")&&!e.match(g))return!1;var t,a=new Date;return e.match("today")||(t=e.split("-"),a.setFullYear(t[0]),a.setMonth(t[1]-1),a.setDate(t[2])),a},y.prototype._hooks={required:function(e){var t=e.value;return"checkbox"===e.type||"radio"===e.type?e.checked===!0:null!==t&&""!==t},"default":function(e,t){return e.value!==t},matches:function(e,t){var a=this.form[t];return a?e.value===a.value:!1},valid_email:function(e){return u.test(e.value)},valid_emails:function(e){for(var t=e.value.split(/\s*,\s*/g),a=0,n=t.length;n>a;a++)if(!u.test(t[a]))return!1;return!0},min_length:function(e,t){return i.test(t)?e.value.length>=parseInt(t,10):!1},max_length:function(e,t){return i.test(t)?e.value.length<=parseInt(t,10):!1},exact_length:function(e,t){return i.test(t)?e.value.length===parseInt(t,10):!1},greater_than:function(e,t){return l.test(e.value)?parseFloat(e.value)>parseFloat(t):!1},less_than:function(e,t){return l.test(e.value)?parseFloat(e.value)=0;i--){var r=s.charAt(i);a=parseInt(r,10),n&&(a*=2)>9&&(a-=9),t+=a,n=!n}return t%10===0},is_file_type:function(e,t){if("file"!==e.type)return!0;var a=e.value.substr(e.value.lastIndexOf(".")+1),n=t.split(","),s=!1,i=0,r=n.length;for(i;r>i;i++)a==n[i]&&(s=!0);return s},greater_than_date:function(e,t){var a=this._getValidDate(e.value),n=this._getValidDate(t);return n&&a?a>n:!1},less_than_date:function(e,t){var a=this._getValidDate(e.value),n=this._getValidDate(t);return n&&a?n>a:!1},greater_than_or_equal_date:function(e,t){var a=this._getValidDate(e.value),n=this._getValidDate(t);return n&&a?a>=n:!1},less_than_or_equal_date:function(e,t){var a=this._getValidDate(e.value),n=this._getValidDate(t);return n&&a?n>=a:!1}},e.FormValidator=y}(window,document),"undefined"!=typeof module&&module.exports&&(module.exports=FormValidator);