I am using a validation to reject any string containing <p> or <p> (equivalent in html characters of the p html tag).
I tried with a string that did contain it and strings with <p> tag are rejected but not those with <p>
validates_format_of :message_content,
:with => /\A((?!<p>).)*\z/i,
:message => "pb1"
validates_format_of :message_content,
:with => /\A((?!<p>).)*\z/i,
:message => "pb2"
Should I escape some of the special characters of !<p> ,which could create issues for the regexp ? How ?
r = Regexp.new("<p>|<p>") #=> /<p>|<p>/work (i.e.,str !~ r)?sanitizehelper. Insert something likebefore_validation :sanitize_content, :on => :createand then in yoursanitize_contentmethod useActionController::Base.helpers.sanitize(field, tags)configured appropriately. Your meager attempt at preventingptags is easily fooled (e.g. by whitespace< p>)