# Validate\_format\_of except=\>?

**URL:** <https://www.ruby-forum.com/t/validate-format-of-except/114428>\
**Category:** Rails\
**Created:** [September 12, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/validate-format-of-except/114428 "2007-09-12T16:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 12, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/validate-format-of-except/114428/1 "2007-09-12T16:41:02Z")

</div>

Hi all,

I do a save on some user information in controller called my\_controller.  
In my model for User I have a validation for the password:

validates\_format\_of :password, :with =\> /^\w+$/, :message =\> ‘ **Password must be alphanumeric** ’, :on =\> :save

What I need to do, in this case, is to validate the save except for when  
the save is called by this method in this controller. For example, I  
would like to say:

validates\_format\_of :password, :with =\> /^\w+$/, :message =\> ‘ **Password must be alphanumeric** ’, :on =\> :save, except =\>  
[:submit]

However, the problem here is that :submit is the name for a method in  
the controller and not the model where this validation is taking place.  
And because I never pass the password along as a parameter, the  
validation always fails. Is there a way to do this? Thanks,

-Shandy

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [September 12, 2007, 5:15pm UTC](https://www.ruby-forum.com/t/validate-format-of-except/114428/2 "2007-09-12T17:15:58Z")

</div>

On 9/12/07, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the save is called by this method in this controller. For example, I  
> would like to say:
> 
> validates\_format\_of :password, :with =\> /^\w+$/, :message =\> ‘ **Password must be alphanumeric** ’, :on =\> :save, except =\>  
> [:submit]
> 
> However, the problem here is that :submit is the name for a method in  
> the controller and not the model where this validation is taking place.  
> And because I never pass the password along as a parameter, the  
> validation always fails. Is there a way to do this? Thanks,

Don’t try to make the model behavior on a controller action name.

This problem has been solved by others. Study a plugin like  
acts\_as\_authenticated to see how they do it.
