SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validation on special characters

    Hello,

    I'm trying to make a validation that catches special latin chars that cause Mysql errors.

    Here's what I've been trying so far:

    validates_format_of :title, :with=>/\A[^#]/, :message=>'must not start with a "#"', :if => Proc.new {|page| page.title && page.title.size > 0 }

    validates_exclusion_of :title, :in => 'π ≤ ≥ ∫ √ ≈ Ω ∞ ≠ ∑ ∂ ∆ ˙ ˚', :message => "Title contains invalid characters"

    When I throw these characters into the textfield, they aren't dectected and the sql error is thrown.

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2006
    Location
    Halifax, Canada
    Posts
    498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think validates_exclusion_of will only work if one of the :in parameters exactly matches the field value. It makes more sense to use a regex here instead.

    Perhaps something like:

    Code:
    validates_format_of :title, :with => /\A[^π≤≥∫√≈Ω∞≠∑∂∆˙˚]+\Z/, :message => "Title contains invalid characters"
    Paul Butler.org
    JSSpamBlock - Reduce WordPress spam.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •