Displaying 20 results from an estimated 113 matches for "validates_format_of".
2008 Jun 07
3
DRY validates_format_of?
In a model I have following validates_format_of. Is there an easy way to
DRY this up? It seems to be rather repetitive.
validates_format_of :expiration_date, :with =>
/^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/
validates_format_of :activation_date, :with =>
/^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/
validates_format_of :some_oth...
2006 Sep 10
1
validates_format_of :something, :with => /REGEX/
...vented in any ''civilisation'', and the fact that we still have
to dirty our minds with this in Rails is something that (sh/c)ould
ideally be corrected in Rails (preferably before the release of 1.2
(?)) or in the form of a plugin.
A very common scenario in Rails models are:
validates_format_of :name,
:with => [ only characters that are commonly found in Names,
ie: NOT {^%$([]\/><?;* ) ]
validates_format_of :email,
:with => [ valid email format & characters ]
validates_format_of :url,
:with => [ valid url format & characters ]
valida...
2005 Nov 28
4
validates_format_of nil
I''ve noticed that validates_format_of will return invalid if the field
is nil.
Question 1) How should we declare a validation that will validate it
with a regex if it is set, but, if the field is not set, just move on
Question 2) Why is it done this way? The other validators are only
invoked if the field is set . If you want to...
2012 Aug 14
3
validates_format_of :message not working, validates_length_of :message is working
I''m using validates_format_of and the validation I want to do works, but I
can''t get an error message to be displayed if the data is invalid:
validates_format_of :mobile, :with => /\A[\+0-9]+\Z/, :message => " - Wrong"
I have another validation some where else that does display the error
message: &qu...
2006 Apr 05
4
validates_format_of ?
...a "price" field and I''m attempting to
validate it and allow some flexibility in the way the user enters it.
It''s a numeric field but I want the user to be able to enter dollar
signs and commas naturally in the data entry.
I''m trying to understand how to use validates_format_of, and I''m not
sure what I''m missing. I''m a beginner at regular expressions but I''ve
been researching it.
I tried an extremely simple case:
validates_format_of :price, :with => /^\d$/
If I understand correctly, this validation should only succeed for a
si...
2008 Feb 24
1
validates_format_of no dots allowed
I need a validates_format_of that disallow dots.
In the api there is nothing to find about how validates_format_of exatly
works.
Is there a better documentation or is there something that can tell me
howto disallow dots.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You rece...
2006 Apr 18
10
Validates_ip_of
Hello all
After being told of a funky date validator I will ask again for another
validator :) Does anyone know of a plugin that validates that a field is
the correct syntax for an IP Address?
Thanks
Jeff
--
Posted via http://www.ruby-forum.com/.
2010 Jan 18
3
validates_format_of :phone,
validates_format_of :phone,
:with => /\A\s*(?:(?:\+?(?:\d{1,3}(?:\s*|[\-.])))?\(?\d{3}[\-\/)]?\s*)
(?:[2-9][0-9 \-.]{6,})\s*\z/,
i pit it on my reuriments but error whlie entering
666.111.9999
i want it should be ok
any one help me please
--
You received this message because you are subscribed to the Google G...
2006 Jan 20
4
validates_format_of > Invalid regular expression with simple pattern
Hello,
I try this :
validates_format_of :name , :with => /^[A-z0-9_.- ]*$/ , :message =>
"bad characters"
for accept any name with chars "A" to "z" , "0" to "9" , with "_" "."
"-" and " "
The pattern is really simple but I have this error...
2006 Jun 14
1
file column validates_format_of
Been manually testing file column with success except it seems to upload
the file before validating it. Also .pdf files (which shouldn''t even
validate) crash WEBrick. What am I missing to solve these problems?
(apart from a brain!)
validates_presence_of :title, :file
validates_format_of :file, :with => %r{.(gif|jpg|png)$}i,
:message => "File must end with .jpg, .gif or .png"
file_column :file, :magick => {
:versions => { "thumb" => "100x100", "medium" => "640x480>" }
}
end
--
Posted via http://www....
2007 Oct 18
0
validates_format_of date
Can someone tell me why this returns ''dob is invalid'' when dob is
''01/01/1969''?
validates_format_of :dob, :with => /[0-9]{2}.[0-9]{2}.[0-9]
{4}/, :message => ''is invalid''
I''m trying to validate a date entred into a form. I suppose there are
different ways to accomplish this, and because it doesn''t work, I''m
going to be using them, but this seem...
2006 Mar 17
0
validates_format_of before type_cast?
...before_type_cast[''date_of_loss''] =~
/^(\d+(-|\/)){2}\d{4}/
errors.add(''date_of_loss'', ''use the form: mm/dd/yyyy'')
end
end
Thanks
(BTW: I know there is a date validation plugin)
--
View this message in context: http://www.nabble.com/validates_format_of-before-type_cast--t1295244.html#a3448544
Sent from the RubyOnRails Users forum at Nabble.com.
2006 Feb 22
0
validates_format_of datetime?
What''s the best way to check a field to ensure it is a valid datetime? I
could validates_format_of :with a regular expression for "yyyy-mm-dd
hh:mm:ss", but I''m wondering if there is a more direct way to do this.
--
Posted via http://www.ruby-forum.com/.
2006 Feb 27
1
Help on validates_format_of
Hello,
i''m quite new with Ruby and i''ve been headbreaking quite a while
on the following question. So I hope somebody can help this Noob on
Rails.
I want to use validates_format_of on the password a user enters for
his or her account. I want it to check on the following:
1.. The password has to have a minimum of 2 non-capitalized characters.
with the characters i mean: a to z
AND
2.. The password has to have a minimum of 2 CAPITALIZED characters.
with the character...
2009 Feb 28
7
be_valid (validates_format_of ..., :on => :create)
Greetings,
How to write Example which will check if model''s variable''s
format is valid using :on => :create, like this:
class User < ActiveRecord::Base
...
validates_format_of :email, :with => /.../, :on => :create
...
Using following code is not right:
it "should ..." do
@user = users(:example_user)
@user.email = ''invalid_email_format''
@user.save
@user.should_not be_valid
end
Even those code is not right:
it "sh...
2005 Aug 10
5
validates_format_of on an optional field using :if
Hi there,
I''ve got the following in my model:
validates_format_of :postcode,
:with => /^([a-zA-Z]{1,2}[0-9]{1,2} [0-9]{1}[a-zA-Z]{2})$/,
:message => "is not valid",
:if => :postcode
... but it''s not working - it always insists on validation, even if postcode
is empty. Basically, the postcode field is optional, but if it''s f...
2007 Feb 16
13
negate the regexp in validates_format_of
...ame.
However, the newbies might not know how to write a regexp that
excludes a match, instead of tests for it. Understand - I''m just
asking this question to help them. I have been using Regexps since
''grep'' on Xenix! But the newbies here might not know how to do this:
validates_format_of :field_must_break, :with => /\n/
validates_format_of :field_must_not_break, :with => /^[^\n]$/
The second one fails with data that correctly have no \n linefeed in them.
How do I - I mean "they" - negate a regexp?
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blo...
2006 May 10
8
E-mail validtor??
Does anyone have a good working e-mail validator? or even some regexp to
make the validates_format_of work right... that would be awesome. Also,
maybe an online tutorial for regexp. i''ve always been afraid of it but i
think it''s time to face the fears.
thanks!
--
Posted via http://www.ruby-forum.com/.
2006 Apr 12
2
Inverting validates_format_of
I''ve got a regex validation on one of the inputs to my application, a
file path. Now these only ever come from trusted users
(administrators), but it would still be good to catch the most obvious
attempts at directory traversal, etc.
I''ve already got a regex that only allows \w then -, . and /. However,
I want to stop two dots in a row, so I was wondering how to make the
2006 Jan 19
4
validates_presence_of
I am just going through the book and I come across a problem with the
code in the app/models:
validates_format_of :image_url,
:with => %r{^http:.+\.(gif|jpg|png)$}i,
:message => "must be a URL for a GIF, JPG, or PNG image"
It seems to moan when it''s empty even though I removed :image_url from
validates_presence_of. How should I make it optional? Altering the
regex?
Bt...