From: karland Date: Fri, 4 Nov 2016 10:05:46 +0000 (+0100) Subject: Add Builtin Pattern to Abide docs X-Git-Tag: v6.3-rc1~36^2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=195cedd4cd7e09a9547d4475f7671456585425f8;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Add Builtin Pattern to Abide docs --- diff --git a/docs/pages/abide.md b/docs/pages/abide.md index 0f7f58626..f2d4d5301 100644 --- a/docs/pages/abide.md +++ b/docs/pages/abide.md @@ -198,6 +198,72 @@ $("#bar").on("formvalid.zf.abide", function(ev,frm) { // do something perhaps }); ``` + +## Builtin Patterns and Validators + +The following patterns and validators are already built in: + +`alpha`, +`alpha_numeric`, +`card`, +`color` +`cvv`, +`date`, +`dateISO`, +`datetime`, +`day_month_year`, +`domain`, +`email`, +`integer`, +`month_day_year`, +`number`, +`time`, +`url` + +They are defined by regular expressions as you can see below. Note, that the patterns that relate to text such as `alpha` and `alpha_numeric` do not consider special characters from other languages. You need to add these special characters yourself to the regular expressions. For instance, for the German language you need to add: + +```JS +alpha : /^[a-zäöüßA-ZÄÖÜ]+$/, +alpha_numeric : /^[a-zäöüßA-ZÄÖÜ0-9]+$/, +``` + +Then you need to customize the builtin pattern as explained in the next session. Otherwise Abide will produce an error if a special character is input in your text field which is validated with `pattern="alpha"` or `pattern="alpha_numeric"`. + +Here is the definition of the builtin patterns: + +```JS +alpha : /^[a-zA-Z]+$/, +alpha_numeric : /^[a-zA-Z0-9]+$/, +integer : /^[-+]?\d+$/, +number : /^[-+]?\d*(?:[\.\,]\d+)?$/, + +// amex, visa, diners +card : /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/, +cvv : /^([0-9]){3,4}$/, + +// http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address +email : /^[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])?)+$/, + +url : /^(https?|ftp|file|ssh):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/, +// abc.de +domain : /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,8}$/, + +datetime : /^([0-2][0-9]{3})\-([0-1][0-9])\-([0-3][0-9])T([0-5][0-9])\:([0-5][0-9])\:([0-5][0-9])(Z|([\-\+]([0-1][0-9])\:00))$/, +// YYYY-MM-DD +date : /(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))$/, +// HH:MM:SS +time : /^(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]){2}$/, +dateISO : /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/, +// MM/DD/YYYY +month_day_year : /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.]\d{4}$/, +// DD/MM/YYYY +day_month_year : /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.]\d{4}$/, + +// #FFF or #FFFFFF +color : /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/ +``` + + ## Adding Custom Pattern and Validator * Override builtin patterns and validators before foundation is initialized * Add new patterns and validators before or after foundation is initialized