# Validations

**URL:** <https://www.ruby-forum.com/t/validations/120965>\
**Category:** Rails\
**Created:** [November 22, 2007, 8:13am UTC](https://www.ruby-forum.com/t/validations/120965 "2007-11-22T08:13:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@Sameer\_I](https://www.ruby-forum.com/u/Sameer_I)\
**Post date:** [November 22, 2007, 8:13am UTC](https://www.ruby-forum.com/t/validations/120965/1 "2007-11-22T08:13:54Z")

</div>

Hi,

I have a question related to validations. My user table has a password  
field. I have some validations related to password field in my model  
file for this table (user.rb). I have a typical form to change password  
form where I have three fields namely current password, new password and  
retype password.

My validations for other forms work, but those forms are one for each  
table. For this particular form, validations don’t work. Do I have to  
write separate validations for this form in action or can I reuse these  
validations in some way? If there is some other way, please elaborate.

– password related validation defs from user.rb –

attr\_accessor :password  
validates\_presence\_of :password, :password\_confirmation, :if =\>  
:password\_required?, :message =\> “Password cannot be blank”  
validates\_length\_of :password, :within =\> 8…32, :if =\>  
:password\_required?  
validates\_confirmation\_of :password, :if =\> :password\_required?,  
:message =\> “New password and retyped password don’t match”

– password related validation defs from user.rb end here –

Thank you.

:wq Sameer.
