ソースを参照

adds new phone validator

Gercek Karakus 12 年 前
コミット
c163d2540a
1 ファイル変更21 行追加0 行削除
  1. 21 0
      src/js/validator/phone.js

+ 21 - 0
src/js/validator/phone.js

@@ -0,0 +1,21 @@
+(function($) {
+    $.fn.bootstrapValidator.validators.phone = {
+        /**
+         * Return true if the input value contains a valid US phone number only
+         *
+         * @param {BootstrapValidator} validator Validate plugin instance
+         * @param {jQuery} $field Field element
+         * @param {Object} options
+         * @returns {Boolean}
+         */
+        validate: function(validator, $field, options) {
+            var value = $field.val();
+            if (value == '') {
+                return true;
+            }
+
+            value = value.replace(/\(|\)|\s+/g, '');
+            return (/^(?:1\-?)?(\d{3})[\-\.]?(\d{3})[\-\.]?(\d{4})$/).test(value);
+        }
+    }
+}(window.jQuery));