bootstrapValidator.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. /**
  2. * BootstrapValidator v0.1.1-dev (http://github.com/nghuuphuoc/bootstrapvalidator)
  3. *
  4. * A jQuery plugin to validate form fields. Use with Bootstrap 3
  5. *
  6. * @author Nguyen Huu Phuoc <phuoc@huuphuoc.me>
  7. * @copyright (c) 2013 Nguyen Huu Phuoc
  8. * @license MIT
  9. */
  10. (function($) {
  11. var BootstrapValidator = function(form, options) {
  12. this.$form = $(form);
  13. this.options = $.extend({}, BootstrapValidator.DEFAULT_OPTIONS, options);
  14. this.invalidFields = {};
  15. this.xhrRequests = {};
  16. this.numPendingRequests = null;
  17. this.formSubmited = false;
  18. this._init();
  19. };
  20. // The default options
  21. BootstrapValidator.DEFAULT_OPTIONS = {
  22. // The form CSS class
  23. elementClass: 'bootstrap-validator-form',
  24. // Default invalid message
  25. message: 'This value is not valid',
  26. // The submit buttons selector
  27. // These buttons will be disabled when the form input are invalid
  28. submitButtons: 'button[type="submit"]',
  29. // Map the field name with validator rules
  30. fields: null
  31. };
  32. BootstrapValidator.prototype = {
  33. constructor: BootstrapValidator,
  34. /**
  35. * Init form
  36. */
  37. _init: function() {
  38. if (this.options.fields == null) {
  39. return;
  40. }
  41. var that = this;
  42. this.$form
  43. .addClass(this.options.elementClass)
  44. .on('submit', function(e) {
  45. that.formSubmited = true;
  46. if (that.options.fields) {
  47. for (var field in that.options.fields) {
  48. if (that.numPendingRequests > 0 || that.numPendingRequests == null) {
  49. // Check if the field is valid
  50. var $field = that.getFieldElement(field);
  51. if ($field.data('bootstrapValidator.isValid') !== true) {
  52. that.validateField(field);
  53. }
  54. }
  55. }
  56. if (!that.isValid()) {
  57. that.$form.find(that.options.submitButtons).attr('disabled', 'disabled');
  58. e.preventDefault();
  59. }
  60. }
  61. });
  62. for (var field in this.options.fields) {
  63. this._initField(field);
  64. }
  65. },
  66. /**
  67. * Init field
  68. *
  69. * @param {String} field The field name
  70. */
  71. _initField: function(field) {
  72. if (this.options.fields[field] == null || this.options.fields[field].validators == null) {
  73. return;
  74. }
  75. var $field = this.getFieldElement(field);
  76. if (null == $field) {
  77. return;
  78. }
  79. // Create a help block element for showing the error
  80. var that = this,
  81. $parent = $field.parents('.form-group'),
  82. helpBlock = $parent.find('.help-block');
  83. if (helpBlock.length == 0) {
  84. var $small = $('<small/>').addClass('help-block').appendTo($parent);
  85. $field.data('bootstrapValidator.error', $small);
  86. // Calculate the number of columns of the label/field element
  87. // Then set offset to the help block element
  88. var label, cssClasses, offset;
  89. if (label = $parent.find('label').get(0)) {
  90. cssClasses = $(label).attr('class').split(' ');
  91. for (var i = 0; i < cssClasses.length; i++) {
  92. if (cssClasses[i].substr(0, 7) == 'col-lg-') {
  93. offset = cssClasses[i].substr(7);
  94. break;
  95. }
  96. }
  97. } else {
  98. cssClasses = $parent.children().eq(0).attr('class').split(' ');
  99. for (var i = 0; i < cssClasses.length; i++) {
  100. if (cssClasses[i].substr(0, 14) == 'col-lg-offset-') {
  101. offset = cssClasses[i].substr(14);
  102. break;
  103. }
  104. }
  105. }
  106. if (offset) {
  107. $small.addClass('col-lg-offset-' + offset).addClass('col-lg-' + parseInt(12 - offset));
  108. }
  109. } else {
  110. $field.data('bootstrapValidator.error', helpBlock.eq(0));
  111. }
  112. var type = $field.attr('type'),
  113. event = ('checkbox' == type || 'radio' == type) ? 'change' : 'keyup';
  114. $field.on(event, function() {
  115. that.formSubmited = false;
  116. that.validateField(field);
  117. });
  118. },
  119. /**
  120. * Get field element
  121. *
  122. * @param {String} field The field name
  123. * @returns {jQuery}
  124. */
  125. getFieldElement: function(field) {
  126. var fields = this.$form.find('[name="' + field + '"]');
  127. return (fields.length == 0) ? null : $(fields[0]);
  128. },
  129. /**
  130. * Validate given field
  131. *
  132. * @param {String} field The field name
  133. */
  134. validateField: function(field) {
  135. var $field = this.getFieldElement(field);
  136. if (null == $field) {
  137. // Return if cannot find the field with given name
  138. return;
  139. }
  140. var that = this,
  141. validators = that.options.fields[field].validators;
  142. for (var validatorName in validators) {
  143. if (!$.fn.bootstrapValidator.validators[validatorName]) {
  144. continue;
  145. }
  146. var isValid = $.fn.bootstrapValidator.validators[validatorName].validate(that, $field, validators[validatorName]);
  147. if (isValid === false) {
  148. that.showError($field, validatorName);
  149. break;
  150. } else if (isValid === true) {
  151. that.removeError($field);
  152. }
  153. }
  154. },
  155. /**
  156. * Show field error
  157. *
  158. * @param {jQuery} $field The field element
  159. * @param {String} validatorName
  160. */
  161. showError: function($field, validatorName) {
  162. var field = $field.attr('name'),
  163. validator = this.options.fields[field].validators[validatorName],
  164. message = validator.message || this.options.message,
  165. $parent = $field.parents('.form-group');
  166. this.invalidFields[field] = true;
  167. // Add has-error class to parent element
  168. $parent.removeClass('has-success').addClass('has-error');
  169. $field.data('bootstrapValidator.error').html(message).show();
  170. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  171. },
  172. /**
  173. * Remove error from given field
  174. *
  175. * @param {jQuery} $field The field element
  176. */
  177. removeError: function($field) {
  178. delete this.invalidFields[$field.attr('name')];
  179. $field.parents('.form-group').removeClass('has-error').addClass('has-success');
  180. $field.data('bootstrapValidator.error').hide();
  181. this.$form.find(this.options.submitButtons).removeAttr('disabled');
  182. },
  183. /**
  184. * Start remote checking
  185. *
  186. * @param {jQuery} $field The field element
  187. * @param {String} validatorName
  188. * @param {XMLHttpRequest} xhr
  189. */
  190. startRequest: function($field, validatorName, xhr) {
  191. var field = $field.attr('name');
  192. $field.data('bootstrapValidator.isValid', false);
  193. this.$form.find(this.options.submitButtons).attr('disabled', 'disabled');
  194. if(this.numPendingRequests == null){
  195. this.numPendingRequests = 0;
  196. }
  197. this.numPendingRequests++;
  198. // Abort the previous request
  199. if (!this.xhrRequests[field]) {
  200. this.xhrRequests[field] = {};
  201. }
  202. if (this.xhrRequests[field][validatorName]) {
  203. this.numPendingRequests--;
  204. this.xhrRequests[field][validatorName].abort();
  205. }
  206. this.xhrRequests[field][validatorName] = xhr;
  207. },
  208. /**
  209. * Complete remote checking
  210. *
  211. * @param {jQuery} $field The field element
  212. * @param {String} validatorName
  213. * @param {boolean} isValid
  214. */
  215. completeRequest: function($field, validatorName, isValid) {
  216. if (isValid === false) {
  217. this.showError($field, validatorName);
  218. } else if (isValid === true) {
  219. this.removeError($field);
  220. $field.data('bootstrapValidator.isValid', true);
  221. }
  222. var field = $field.attr('name');
  223. delete this.xhrRequests[field][validatorName];
  224. this.numPendingRequests--;
  225. if (this.numPendingRequests <= 0) {
  226. this.numPendingRequests = 0;
  227. if (this.formSubmited) {
  228. this.$form.submit();
  229. }
  230. }
  231. },
  232. /**
  233. * Check the form validity
  234. *
  235. * @returns {boolean}
  236. */
  237. isValid: function() {
  238. if (this.numPendingRequests > 0) {
  239. return false;
  240. }
  241. for (var field in this.invalidFields) {
  242. if (this.invalidFields[field]) {
  243. return false;
  244. }
  245. }
  246. return true;
  247. }
  248. };
  249. // Plugin definition
  250. $.fn.bootstrapValidator = function(options) {
  251. return this.each(function() {
  252. var $this = $(this), data = $this.data('bootstrapValidator');
  253. if (!data) {
  254. $this.data('bootstrapValidator', (data = new BootstrapValidator(this, options)));
  255. }
  256. });
  257. };
  258. // Available validators
  259. $.fn.bootstrapValidator.validators = {};
  260. $.fn.bootstrapValidator.Constructor = BootstrapValidator;
  261. }(window.jQuery));
  262. ;(function($) {
  263. $.fn.bootstrapValidator.validators.between = {
  264. /**
  265. * Return true if the input value is between (strictly or not) two given numbers
  266. *
  267. * @param {BootstrapValidator} validator The validator plugin instance
  268. * @param {jQuery} $field Field element
  269. * @param {Object} options Can consist of the following keys:
  270. * - min
  271. * - max
  272. * - inclusive [optional]: Can be true or false. Default is true
  273. * - message: The invalid message
  274. * @returns {boolean}
  275. */
  276. validate: function(validator, $field, options) {
  277. var value = parseFloat($field.val());
  278. return (options.inclusive === true)
  279. ? (value > options.min && value < options.max)
  280. : (value >= options.min && value <= options.max);
  281. }
  282. };
  283. }(window.jQuery));
  284. ;(function($) {
  285. $.fn.bootstrapValidator.validators.digits = {
  286. /**
  287. * Return true if the input value contains digits only
  288. *
  289. * @param {BootstrapValidator} validator Validate plugin instance
  290. * @param {jQuery} $field Field element
  291. * @param {Object} options
  292. * @returns {boolean}
  293. */
  294. validate: function(validator, $field, options) {
  295. return /^\d+$/.test($field.val());
  296. }
  297. }
  298. }(window.jQuery));
  299. ;(function($) {
  300. $.fn.bootstrapValidator.validators.emailAddress = {
  301. /**
  302. * Return true if and only if the input value is a valid email address
  303. *
  304. * @param {BootstrapValidator} validator Validate plugin instance
  305. * @param {jQuery} $field Field element
  306. * @param {Object} options
  307. * @returns {boolean}
  308. */
  309. validate: function(validator, $field, options) {
  310. var value = $field.val(),
  311. // Email address regular expression
  312. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  313. emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  314. return emailRegExp.test(value);
  315. }
  316. }
  317. }(window.jQuery));
  318. ;(function($) {
  319. $.fn.bootstrapValidator.validators.greaterThan = {
  320. /**
  321. * Return true if the input value is greater than or equals to given number
  322. *
  323. * @param {BootstrapValidator} validator Validate plugin instance
  324. * @param {jQuery} $field Field element
  325. * @param {Object} options Can consist of the following keys:
  326. * - value: The number used to compare to
  327. * - inclusive [optional]: Can be true or false. Default is true
  328. * - message: The invalid message
  329. * @returns {boolean}
  330. */
  331. validate: function(validator, $field, options) {
  332. var value = parseFloat($field.val());
  333. return (options.inclusive === true) ? (value > options.value) : (value >= options.value);
  334. }
  335. }
  336. }(window.jQuery));
  337. ;(function($) {
  338. $.fn.bootstrapValidator.validators.hexColor = {
  339. /**
  340. * Return true if the input value is a valid hex color
  341. *
  342. * @param {BootstrapValidator} validator The validator plugin instance
  343. * @param {jQuery} $field Field element
  344. * @param {Object} options Can consist of the following keys:
  345. * - message: The invalid message
  346. * @returns {boolean}
  347. */
  348. validate: function(validator, $field, options) {
  349. var value = $field.val();
  350. return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(value);
  351. }
  352. };
  353. }(window.jQuery));
  354. ;(function($) {
  355. $.fn.bootstrapValidator.validators.identical = {
  356. /**
  357. * Check if input value equals to value of particular one
  358. *
  359. * @param {BootstrapValidator} validator The validator plugin instance
  360. * @param {jQuery} $field Field element
  361. * @param {Object} options Consists of the following key:
  362. * - field: The name of field that will be used to compare with current one
  363. * @returns {boolean}
  364. */
  365. validate: function(validator, $field, options) {
  366. var value = $field.val(),
  367. $compareWith = validator.getFieldElement(options.field);
  368. if ($compareWith && value == $compareWith.val()) {
  369. validator.removeError($compareWith);
  370. return true;
  371. } else {
  372. return false;
  373. }
  374. }
  375. };
  376. }(window.jQuery));
  377. ;(function($) {
  378. $.fn.bootstrapValidator.validators.lessThan = {
  379. /**
  380. * Return true if the input value is less than or equal to given number
  381. *
  382. * @param {BootstrapValidator} validator The validator plugin instance
  383. * @param {jQuery} $field Field element
  384. * @param {Object} options Can consist of the following keys:
  385. * - value: The number used to compare to
  386. * - inclusive [optional]: Can be true or false. Default is true
  387. * - message: The invalid message
  388. * @returns {boolean}
  389. */
  390. validate: function(validator, $field, options) {
  391. var value = parseFloat($field.val());
  392. return (options.inclusive === true) ? (value < options.value) : (value <= options.value);
  393. }
  394. };
  395. }(window.jQuery));
  396. ;(function($) {
  397. $.fn.bootstrapValidator.validators.notEmpty = {
  398. /**
  399. * Check if input value is empty or not
  400. *
  401. * @param {BootstrapValidator} validator The validator plugin instance
  402. * @param {jQuery} $field Field element
  403. * @param {Object} options
  404. * @returns {boolean}
  405. */
  406. validate: function(validator, $field, options) {
  407. var type = $field.attr('type');
  408. return ('checkbox' == type || 'radio' == type) ? $field.is(':checked') : ($.trim($field.val()) != '');
  409. }
  410. };
  411. }(window.jQuery));
  412. ;(function($) {
  413. $.fn.bootstrapValidator.validators.regexp = {
  414. /**
  415. * Check if the element value matches given regular expression
  416. *
  417. * @param {BootstrapValidator} validator The validator plugin instance
  418. * @param {jQuery} $field Field element
  419. * @param {Object} options Consists of the following key:
  420. * - regexp: The regular expression you need to check
  421. * @returns {boolean}
  422. */
  423. validate: function(validator, $field, options) {
  424. var value = $field.val();
  425. return value.match(options.regexp);
  426. }
  427. };
  428. }(window.jQuery));
  429. ;(function($) {
  430. $.fn.bootstrapValidator.validators.remote = {
  431. /**
  432. * Request a remote server to check the input value
  433. *
  434. * @param {BootstrapValidator} validator Plugin instance
  435. * @param {jQuery} $field Field element
  436. * @param {Object} options Can consist of the following keys:
  437. * - url
  438. * - data [optional]: By default, it will take the value
  439. * {
  440. * <fieldName>: <fieldValue>
  441. * }
  442. * - message: The invalid message
  443. * @returns {string}
  444. */
  445. validate: function(validator, $field, options) {
  446. var value = $field.val(), name = $field.attr('name'), data = options.data;
  447. if (data == null) {
  448. data = {};
  449. data[name] = value;
  450. }
  451. var xhr = $.ajax({
  452. type: 'POST',
  453. url: options.url,
  454. dataType: 'json',
  455. data: data
  456. }).success(function(response) {
  457. var isValid = response.valid === true || response.valid === 'true';
  458. validator.completeRequest($field, 'remote', isValid);
  459. });
  460. validator.startRequest($field, 'remote', xhr);
  461. return 'pending';
  462. }
  463. };
  464. }(window.jQuery));
  465. ;(function($) {
  466. $.fn.bootstrapValidator.validators.stringLength = {
  467. /**
  468. * Check if the length of element value is less or more than given number
  469. *
  470. * @param {BootstrapValidator} validator The validator plugin instance
  471. * @param {jQuery} $field Field element
  472. * @param {Object} options Consists of following keys:
  473. * - min
  474. * - max
  475. * At least one of two keys is required
  476. * @returns {boolean}
  477. */
  478. validate: function(validator, $field, options) {
  479. var value = $.trim($field.val()), length = value.length;
  480. if ((options.min && length < options.min) || (options.max && length > options.max)) {
  481. return false;
  482. }
  483. return true;
  484. }
  485. };
  486. }(window.jQuery));
  487. ;(function($) {
  488. $.fn.bootstrapValidator.validators.uri = {
  489. /**
  490. * Return true if the input value is a valid URL
  491. *
  492. * @param {BootstrapValidator} validator The validator plugin instance
  493. * @param {jQuery} $field Field element
  494. * @param {Object} options
  495. * @returns {boolean}
  496. */
  497. validate: function(validator, $field, options) {
  498. // Credit to https://gist.github.com/dperini/729294
  499. //
  500. // Regular Expression for URL validation
  501. //
  502. // Author: Diego Perini
  503. // Updated: 2010/12/05
  504. //
  505. // the regular expression composed & commented
  506. // could be easily tweaked for RFC compliance,
  507. // it was expressly modified to fit & satisfy
  508. // these test for an URL shortener:
  509. //
  510. // http://mathiasbynens.be/demo/url-regex
  511. //
  512. // Notes on possible differences from a standard/generic validation:
  513. //
  514. // - utf-8 char class take in consideration the full Unicode range
  515. // - TLDs have been made mandatory so single names like "localhost" fails
  516. // - protocols have been restricted to ftp, http and https only as requested
  517. //
  518. // Changes:
  519. //
  520. // - IP address dotted notation validation, range: 1.0.0.0 - 223.255.255.255
  521. // first and last IP address of each class is considered invalid
  522. // (since they are broadcast/network addresses)
  523. //
  524. // - Added exclusion of private, reserved and/or local networks ranges
  525. //
  526. // Compressed one-line versions:
  527. //
  528. // Javascript version
  529. //
  530. // /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/i
  531. //
  532. // PHP version
  533. //
  534. // _^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?$_iuS
  535. var urlExp = new RegExp(
  536. "^" +
  537. // protocol identifier
  538. "(?:(?:https?|ftp)://)" +
  539. // user:pass authentication
  540. "(?:\\S+(?::\\S*)?@)?" +
  541. "(?:" +
  542. // IP address exclusion
  543. // private & local networks
  544. "(?!10(?:\\.\\d{1,3}){3})" +
  545. "(?!127(?:\\.\\d{1,3}){3})" +
  546. "(?!169\\.254(?:\\.\\d{1,3}){2})" +
  547. "(?!192\\.168(?:\\.\\d{1,3}){2})" +
  548. "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
  549. // IP address dotted notation octets
  550. // excludes loopback network 0.0.0.0
  551. // excludes reserved space >= 224.0.0.0
  552. // excludes network & broacast addresses
  553. // (first & last IP address of each class)
  554. "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
  555. "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
  556. "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
  557. "|" +
  558. // host name
  559. "(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
  560. // domain name
  561. "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
  562. // TLD identifier
  563. "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
  564. ")" +
  565. // port number
  566. "(?::\\d{2,5})?" +
  567. // resource path
  568. "(?:/[^\\s]*)?" +
  569. "$", "i"
  570. );
  571. return urlExp.test($field.val());
  572. }
  573. };
  574. }(window.jQuery));
  575. ;(function($) {
  576. $.fn.bootstrapValidator.validators.usZipCode = {
  577. /**
  578. * Return true if and only if the input value is a valid US zip code
  579. *
  580. * @param {BootstrapValidator} validator The validator plugin instance
  581. * @param {jQuery} $field Field element
  582. * @param {Object} options
  583. * @returns {boolean}
  584. */
  585. validate: function(validateInstance, $field, options) {
  586. var value = $field.val();
  587. return /^\d{5}([\-]\d{4})?$/.test(value);
  588. }
  589. };
  590. }(window.jQuery));