5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sexy_validations/validators/password.rb', line 5
def self.validate(record, attribute, value, options)
return unless value
unless options.is_a?(Hash)
options = {}
end
options[:length] ||= 6..20
options[:format] ||= /^[\x20-\x7e]+$/i
min = options[:length].min
if value.length < min
record.errors.add(attribute, "zu kurz (mindestes #{min} Zeichen)")
end
max = options[:length].max
if value.length > max
record.errors.add(attribute, "zu lang (maximal #{max} Zeichen)")
end
unless value =~ options[:format]
record.errors.add(attribute, "enthält ungültige Zeichen")
end
end
|