#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    85
    Rep Power
    10

    Ruby form field masking


    Hi,

    I'm wondering if there is a way to apply a mask to a form field with Ruby. For example, a social security number or phone number format. None of my Ruby or Rails books mentions anything about it.

    Thanks!
    ~Snow
  2. #2
  3. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    Edit: I misunderstood.

    No, it's best to do the checking rails-side and flash() if there's a problem, otherwise use javascript.

    You can use some regular expressions for checking.

    ruby Code:
    if ($ssn =~ /\d{7}/) then
        puts "hooray" #their social security number is seven digits (i don't know the exact format, i can help you with the regexp if you give me that though)
    end
    Last edited by LinuxPenguin; August 14th, 2006 at 02:50 PM.

IMN logo majestic logo threadwatch logo seochat tools logo