Sha256: 3531e49e65fac48f8ce6266f066941960e2d34c889dc40215023400c18704811

Contents?: true

Size: 787 Bytes

Versions: 3

Compression:

Stored size: 787 Bytes

Contents

class Regexp
  def to_javascript
    Regexp.new(inspect.sub('\\A','^').sub('\\Z','$').sub('\\z','$').sub(/^\//,'').sub(/\/[a-z]*$/,'').gsub(/\(\?#.+\)/, '').gsub(/\(\?-\w+:/,'('), self.options).inspect
  end
end

module BootstrapValidatorRails
  module Validators
    class Format < Validator
      def generate_data
        data = {}
        return data if unsupported?
        
        options = validator_options

        regex = options[:with].to_javascript
        regex.sub!('/^', '^')
        regex.sub!('$/', '$')
        
        data[:bv_regexp] = 'true'

        if options[:with]
          data[:bv_regexp_regexp] = regex 
        end

        if options[:message]
          data[:bv_regexp_message] = options[:message] 
        end

        data
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bootstrap_validator_rails-0.5.1 lib/bootstrap_validator_rails/validators/format_validator.rb
bootstrap_validator_rails-0.5.0 lib/bootstrap_validator_rails/validators/format_validator.rb
bootstrap_validator_rails-0.4.2 lib/bootstrap_validator_rails/validators/format_validator.rb