[Rails] Re: RegExp error:

2011-08-15 Thread 7stud --
Rafael Ubaldo wrote in post #1016660: It matches because it's true. The expressions states any number of digits before the end of line. It does not state exclusively digits. Wrong. The regex says: 1) match start of line(or just after a newline) 2) match a digit 0 or more times 3) match just

[Rails] Re: RegExp error:

2011-08-15 Thread Frederick Cheung
On Aug 14, 7:29 pm, Misha Ognev li...@ruby-forum.com wrote: Hi! This problem(in model): validates :some_digits_collection, :presence = true, :format = { :with = /^\d*$/, :message = Must contain only digits! } So, :some_digits_collection must match only digits. But when I puts 123f(for

Re: [Rails] Re: RegExp error:

2011-08-15 Thread Dheeraj Kumar
Agreed. @OP: You should try this instead: http://edgeguides.rubyonrails.org/active_record_validations_callbacks.html#numericality On Mon, Aug 15, 2011 at 2:41 PM, Frederick Cheung frederick.che...@gmail.com wrote: On Aug 14, 7:29 pm, Misha Ognev li...@ruby-forum.com wrote: Hi! This

[Rails] Re: RegExp error:

2011-08-15 Thread Misha Ognev
^[1-9]\d*$ Walter, thanks for this. Is this column an integer column? If so, then I seem to recall that at the point that validations run rails has already converted the argument to an integer, i.e. it will have converted your 123f to 123 and so your validation passes. Fred, how I can fix

[Rails] Re: RegExp error:

2011-08-15 Thread Misha Ognev
Dheeraj Kumar, it works, thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email

[Rails] Re: RegExp error:

2011-08-14 Thread Misha Ognev
Perhaps the input value is being cast to an integer for storage, and so the trailing letters are being stripped out. This is one simple way to check this: puts f123 to field. f123.to_i = 0 123f.to_i = 123 But in Rails validation, f123 is validates too. Michael -- Posted via

Re: [Rails] Re: RegExp error:

2011-08-14 Thread Walter Lee Davis
But 0 passes this regex -- it's one digit. If you wanted to ensure that you had n or more digits, you would use a regex like this: ^\d{2,}$ to match two or more digits. Or, you could check to see if the first digit was larger than a 0 if that first digit cannot ever be 0: ^[1-9]\d*$