validates_format_of :something, :with => /REGEX/

Hi all,

I’m hoping to stir the Rails pot a little bit here, so please go easy with me :wink:

Regular Expressions is the most densely inhumane language construct ever invented 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 ]

validates_format_of :basic_text_block,

		      :with => [ only letters, numbers, punctuations and spaces, but NO HTML or code characters ]

validates_format_of :basic_text_with_textile_block,

		      :with => [ textile approved characters ]

OK, you get the picture, now imagine if it was working like this:

validates_format_of :name,

		      :with => :basic_safe_text    # naming could be different, but...

validates_format_of :email,

		      :with => :email_format

validates_format_of :url,

		      :with => :url_format

validates_format_of : basic_text_block,

		      :with => :basic_text_block_format

validates_format_of :basic_text_with_textile_block,

		      :with => : basic_text_with_textile_block_format

or

validates_format_of :text,

		      :included_chars => %w(a-zA-Z0-9 -';)  # some method for specifying which chars we wish to accept

		      :excluded_chars => %w( * & % $ £ ( ) )  # some method for specifying which chars we wish to exclude

Now that would result in a collective DRY process that would save thousands of programming hours, be the highlight of a Steve Jobs/DHH special event, as well as improve the safety and security of countless rails apps.

Rails have removed the ‘ugliness’ of SQL already, so why not basic commonly used Regexp stuff as well ??

IF this is NOT deemed to be valuable, could some kind soul out there create a single resource page with commonly used RUBY (!!!) regexp versions along the lines outlined above ??

And yes, I have all the Ruby/Rails books, and know all the sites out there, but my brain still struggles with the idiotic language called Regular Expressions, and I’m severely fed up with it, so I’m hoping to be helped, and I know I’m not the only one out there with the same problems!

So IF Regexp is dead easy for you, then please don’t complain at my stupidity, but rather help out and provide clear simple examples that follows along the lines above. You are doing the WORLD a favour then!

Kind regards,

Mats

Mats Persson wrote in post #137598:

Hi all,

I'm hoping to stir the Rails pot a little bit here, so please go easy with me :wink:

Regular Expressions is the most densely inhumane language construct ever invented 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.

---- "TextMate, coding with an incredible sense of joy and ease" - www.macromates.com -

Ha. 2006, this was posted 5 years ago man. I hate regex, I agree with you. I think nothing has changed on that aspect.

I just had to reply, I'm know looking for similar stuff.

Cheers!