chuckya/app/validators/regexp_syntax_validator.rb
noellabo 45279418c5
Add reject pattern to Admin setting (Ported to Glitch Soc)
# Conflicts:
#	app/views/admin/settings/shared/_links.html.haml
#	config/routes/admin.rb
2024-02-17 09:39:59 -06:00

13 lines
340 B
Ruby

# frozen_string_literal: true
class RegexpSyntaxValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
begin
Regexp.compile(value)
rescue RegexpError => e
record.errors.add(attribute, I18n.t('applications.invalid_regexp', message: e.message))
end
end
end