Browse Source

#168: Cleanup, update the Changelog

phuoc 11 years ago
parent
commit
e934af3d54
6 changed files with 37 additions and 43 deletions
  1. 4 0
      CHANGELOG.md
  2. 1 1
      bootstrapValidator.jquery.json
  3. 1 1
      bower.json
  4. 1 1
      package.json
  5. 13 18
      src/js/validator/siren.js
  6. 17 22
      src/js/validator/siret.js

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 # Change Log
 
+## v0.4.2 (not released yet)
+
+* [#168](https://github.com/nghuuphuoc/bootstrapvalidator/pull/168): Add siren and siret validators, thanks to [@jswale](https://github.com/jswale)
+
 ## v0.4.1 (2014-04-12)
 
 * [#144](https://github.com/nghuuphuoc/bootstrapvalidator/issues/144), [#158](https://github.com/nghuuphuoc/bootstrapvalidator/issues/158): Fixed an issue that the custom submit handler is not fired from the second time

+ 1 - 1
bootstrapValidator.jquery.json

@@ -1,6 +1,6 @@
 {
     "name": "bootstrapValidator",
-    "version": "0.4.1",
+    "version": "0.4.2-dev",
     "title": "BootstrapValidator",
     "author": {
         "name": "Nguyen Huu Phuoc",

+ 1 - 1
bower.json

@@ -1,7 +1,7 @@
 {
     "name": "bootstrapValidator",
     "description": "The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3",
-    "version": "0.4.1",
+    "version": "0.4.2-dev",
     "main": [
         "dist/css/bootstrapValidator.css",
         "dist/js/bootstrapValidator.js"

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name": "bootstrapValidator",
-    "version": "0.4.1",
+    "version": "0.4.2-dev",
     "description": "The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3",
     "keywords": ["jQuery", "plugin", "validate", "validator", "form", "Bootstrap"],
     "author": {

+ 13 - 18
src/js/validator/siren.js

@@ -1,18 +1,12 @@
-;(function($) {
+(function($) {
 	$.fn.bootstrapValidator.validators.siret = {
-		html5Attributes : {
-			'message' : 'message'
-		},
-
 		/**
-		 * Check if a string is a siren
+		 * 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
+		 * @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) {
@@ -21,16 +15,17 @@
 				return true;
 			}
 
-			var sum = 0;
-			var tmp;
-			for (var cpt = 0; cpt < value.length; cpt++) {
-				if ((cpt % 2) == 1) {
-					tmp = value.charAt(cpt) * 2;
+			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(cpt);
+					tmp = value.charAt(i);
 				}
 				sum += parseInt(tmp);
 			}

+ 17 - 22
src/js/validator/siret.js

@@ -1,36 +1,31 @@
-;(function($) {
+(function($) {
 	$.fn.bootstrapValidator.validators.siret = {
-		html5Attributes : {
-			'message' : 'message'
-		},
-
-		/**
-		 * Check if a string is a siret
-		 *
-		 * @param {BootstrapValidator}
-		 *          validator The validator plugin instance
-		 * @param {jQuery}
-		 *          $field Field element
-		 * @param {Object}
-		 *          options Consist of key: - message: The invalid message
-		 * @returns {Boolean}
-		 */
+        /**
+         * 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;
-			var tmp;
-			for (var cpt = 0; cpt < value.length; cpt++) {
-				if ((cpt % 2) == 0) {
-					tmp = value.charAt(cpt) * 2;
+			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(cpt);
+					tmp = value.charAt(i);
 				}
 				sum += parseInt(tmp);
 			}