Con
(Con)
1
Sijo, what is the correct format for a name? In any case, your regular expression
says that the format for the name should be a comma. Thus, you might want to
rework your regular expression so that it supports the correct naming format.
Good luck,
-Conrad
11175
(-- --)
2
Hi
I got an answer to use this
/(?>\w+\s*(?=,))+/
(A regex that does not contain comma - Ruby - Ruby-Forum)
But this in the unless case dont know how to negate this?
Thanks
Sijo
11175
(-- --)
3
Conrad Taylor wrote:
[...]
Sijo, what is the correct format for a name? In any case, your regular
expression
says that the format for the name should be a comma.
No, it says that the name should *contain* a comma (although your
brackets are superfluous).
Thus, you might
want
to
rework your regular expression so that it supports the correct naming
format.
Yes indeed. If you are requiring names not to have commas, perhaps you
want /^[^,]*$/ or something.
However, it may be better from a usability perspective to not have this
validation -- instead, just remove the commas from the user's input.
Best,
Con
(Con)
4
Conrad Taylor wrote:
[…]
Sijo, what is the correct format for a name? In any case, your regular
expression
says that the format for the name should be a comma.
No, it says that the name should contain a comma (although your
brackets are superfluous).
validates_format_of :name, :with => /[,]/
is saying that the name should have the pattern, ‘,’. The definition
of ‘validates_format_of’ has the following documentation:
Validates whether the value of the specified attribute is of the
correct form by matching it against the regular expression provided.
His initial regular express had the correct syntax and there wasn’t a problem with
the brackets. However, he wasn’t using the correct regular expression for the type
of names that he wanted to store in his name field.
-Conrad