formvalidation
Version:
The best jQuery plugin to validate form fields. Support Bootstrap, Foundation, Pure, SemanticUI, UIKit and custom frameworks
40 lines (38 loc) • 1.39 kB
JavaScript
/**
* bic validator
*
* @link http://formvalidation.io/validators/bic/
* @author https://twitter.com/nghuuphuoc
* @copyright (c) 2013 - 2015 Nguyen Huu Phuoc
* @license http://formvalidation.io/license/
*/
(function($) {
FormValidation.I18n = $.extend(true, FormValidation.I18n || {}, {
'en_US': {
bic: {
'default': 'Please enter a valid BIC number'
}
}
});
FormValidation.Validator.bic = {
/**
* Validate an Business Identifier Code (BIC), also known as ISO 9362, SWIFT-BIC, SWIFT ID or SWIFT code
*
* For more information see http://en.wikipedia.org/wiki/ISO_9362
*
* @todo The 5 and 6 characters are an ISO 3166-1 country code, this could also be validated
* @param {FormValidation.Base} validator The validator plugin instance
* @param {jQuery} $field Field element
* @param {Object} options Can consist of the following keys:
* - message: The invalid message
* @returns {Object}
*/
validate: function(validator, $field, options) {
var value = validator.getFieldValue($field, 'bic');
if (value === '') {
return true;
}
return /^[a-zA-Z]{6}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?$/.test(value);
}
};
}(jQuery));