Rails validates_format_of

I want to use validates_format_of to validate a comma separated string with only letters (small and caps) and numbers.

So.

example1, example2, 22example44, ex24

no: ^ & *, <>, asfasfsdafas <#% $ #

Basically, I want users to enter commas (including numbers) without special characters.

I will use it to verify tags from act_as_taggable_on. (for example, I do not want to be a valid tag.

Thanks in advance.

+3
source share
3 answers

rubular, , tiftiks Tims , .

Tim , , , : -

^\s*[A-Za-z0-9]+(\s*,\s*[A-Za-z0-9]+)*\s*$

, , . : -

array_var = string_var.delete(' ').split(',')
0

^([a-zA-Z0-9]+,\s*)*[a-zA-Z0-9]+$

, , , "abc xyz, fgh qwe". . ^ $, validates_format_of , Rails, .

0
^[A-Za-z0-9]+([ \t]*,[ \t]*[A-Za-z0-9]+)*$

must match a CSV string that contains only these characters, be it just one value or many.

0
source

Source: https://habr.com/ru/post/1737518/


All Articles