Forum: Ruby on Rails help needed on validation format

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A50f246ffcb114ab540fc5b362cab117?d=identicon&s=25 Prashant Jadhav (prashant)
on 2006-12-29 05:29
well
i want to validate the tesxt in a text box in the format(order) of
Quantity,Description,dates

i have wrriten the validation format as
validates_format_of :busage ,
                             :with => /\d,(\w+ \s)\,(\d\d:\d\d:\d\d)/ ,
           :message=>"error of dir"
end

but its still giving error
as its validating date and quantity
but its taking character(\w+) instead of a string  (description)
pls help me out
as whn i put a string in place of description it displays the error


pls help out
Aedb187f1ebbbc22557ade4003869afd?d=identicon&s=25 jdswift (Guest)
on 2006-12-29 09:01
(Received via mailing list)
I think you want:

   /^\d,[\w\s]+,\d\d:\d\d:\d\d$/

That will validate for:
15,Some product description,12:10:06


On Dec 29, 2:29 pm, Prashant Jadhav <rails-mailing-l...@andreas-s.net>
520c24bad2fa9b171d022e3600cd5e58?d=identicon&s=25 Mark Noten (mnoten)
on 2006-12-29 10:03
Hi Jadhav,

You better use this pattern:

/^\d+,\w[\s\w]*,((?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])$/

It will correctly validate the string:

15,Some product description,12:10:06

For validation purposes you don't have to define any capturing groups.
If you want to extract the quantity, description and time then use the
pattern:

/^(\d+),(\w[\s\w]*),(((?:0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]))$/

Best regards,

Mark
This topic is locked and can not be replied to.