浏览代码

Update README with Regexp guide

phuoc 11 年之前
父节点
当前提交
6a18f212b6
共有 4 个文件被更改,包括 80 次插入6 次删除
  1. 4 1
      README.md
  2. 1 1
      dist/css/bootstrapValidator.min.css
  3. 73 2
      dist/js/bootstrapValidator.js
  4. 2 2
      dist/js/bootstrapValidator.min.js

+ 4 - 1
README.md

@@ -62,7 +62,10 @@ Big thanks to the contributors:
 * [@vaz](https://github.com/vaz)
 * [@tomByrer](https://github.com/tomByrer)
 * ... might be you! Let's [fork](https://github.com/nghuuphuoc/bootstrapvalidator/fork) and pull a request!
-  * If you submit new RegEx, please build it using [RegExr.com](http://regexr.com/), add several tests that pass and fail there, and include the "share" link in your JS as a `// ` comment.  Example: `// test: http://regexr.com/38mqi`
+
+> If you submit new RegEx, please build it using [RegExr.com](http://regexr.com/), add several tests that pass and fail there,
+> and include the "share" link in your JS as a ```// ``` comment.
+> For example: ```// Test: http://regexr.com/38mqi```
 
 ## License
 

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -3,7 +3,7 @@
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *
- * @version     v0.4.1
+ * @version     v0.4.2-dev
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 73 - 2
dist/js/bootstrapValidator.js

@@ -3,7 +3,7 @@
  *
  * A jQuery plugin to validate form fields. Use with Bootstrap 3
  *
- * @version     v0.4.1
+ * @version     v0.4.2-dev
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -1799,8 +1799,11 @@
                 case 'US':
                 default:
                     // Make sure US phone numbers have 10 digits
+                    // May start with 1, +1, or 1-; should discard
+                    // Area code may be delimited with (), & sections may be delimited with . or -
+                    // Test: http://regexr.com/38mqi
                     value = value.replace(/\(|\)|\s+/g, '');
-                    return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
+                    return (/^(?:(1\-?)|(\+1 ?))?\(?(\d{3})[\)\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value) && (value.length == 10);
             }
         }
     }
@@ -1900,6 +1903,74 @@
     };
 }(window.jQuery));
 ;(function($) {
+	$.fn.bootstrapValidator.validators.siret = {
+		/**
+		 * Check if a string is a siren number
+		 *
+		 * @param {BootstrapValidator} validator The validator plugin instance
+		 * @param {jQuery} $field Field element
+		 * @param {Object} options Consist of key:
+         * - message: The invalid message
+		 * @returns {Boolean}
+		 */
+		validate : function(validator, $field, options) {
+			var value = $field.val();
+			if (value == '') {
+				return true;
+			}
+
+			var sum    = 0,
+                length = value.length,
+			    tmp;
+			for (var i = 0; i < length; i++) {
+				if ((i % 2) == 1) {
+					tmp = value.charAt(i) * 2;
+					if (tmp > 9) {
+						tmp -= 9;
+					}
+				} else {
+					tmp = value.charAt(i);
+				}
+				sum += parseInt(tmp);
+			}
+			return ((sum % 10) == 0);
+		}
+	};
+}(window.jQuery));;(function($) {
+	$.fn.bootstrapValidator.validators.siret = {
+        /**
+         * Check if a string is a siret number
+         *
+         * @param {BootstrapValidator} validator The validator plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options Consist of key:
+         * - message: The invalid message
+         * @returns {Boolean}
+         */
+		validate : function(validator, $field, options) {
+			var value = $field.val();
+			if (value == '') {
+				return true;
+			}
+
+			var sum    = 0,
+                length = value.length,
+                tmp;
+			for (var i = 0; i < length; i++) {
+				if ((i % 2) == 0) {
+					tmp = value.charAt(i) * 2;
+					if (tmp > 9) {
+						tmp -= 9;
+					}
+				} else {
+					tmp = value.charAt(i);
+				}
+				sum += parseInt(tmp);
+			}
+			return ((sum % 10) == 0);
+		}
+	};
+}(window.jQuery));;(function($) {
     $.fn.bootstrapValidator.validators.step = {
         html5Attributes: {
             message: 'message',

文件差异内容过多而无法显示
+ 2 - 2
dist/js/bootstrapValidator.min.js