Sha256: a54188e4c35348778945dc3101b65ba9292af04d92be7dcf68c7456100e7c1fc

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

(function($) {
    $.fn.bootstrapValidator.i18n.stringCase = $.extend($.fn.bootstrapValidator.i18n.stringCase || {}, {
        'default': 'Please enter only lowercase characters',
        upper: 'Please enter only uppercase characters'
    });

    $.fn.bootstrapValidator.validators.stringCase = {
        html5Attributes: {
            message: 'message',
            'case': 'case'
        },

        /**
         * Check if a string is a lower or upper case one
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Consist of key:
         * - message: The invalid message
         * - case: Can be 'lower' (default) or 'upper'
         * @returns {Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            var stringCase = (options['case'] || 'lower').toLowerCase();
            return {
                valid: ('upper' === stringCase) ? value === value.toUpperCase() : value === value.toLowerCase(),
                message: options.message || (('upper' === stringCase) ? $.fn.bootstrapValidator.i18n.stringCase.upper : $.fn.bootstrapValidator.i18n.stringCase['default'])
            };
        }
    };
}(window.jQuery));

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
bootstrap_validator_rails-0.1.0 vendor/assets/javascripts/validator/stringCase.js
bootstrap_validator_rails-0.0.6 vendor/assets/javascripts/validator/stringCase.js
bootstrap_validator_rails-0.0.5 vendor/assets/javascripts/validator/stringCase.js
bootstrap_validator-rails-0.0.1 vendor/javascripts/validator/stringCase.js