# Custom validation in model

**URL:** <https://www.ruby-forum.com/t/custom-validation-in-model/48909>\
**Category:** Rails\
**Created:** [November 26, 2005, 7:31pm UTC](https://www.ruby-forum.com/t/custom-validation-in-model/48909 "2005-11-26T19:31:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![straightflush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@straightflush](https://www.ruby-forum.com/u/straightflush)\
**Post date:** [November 26, 2005, 7:31pm UTC](https://www.ruby-forum.com/t/custom-validation-in-model/48909/1 "2005-11-26T19:31:41Z")

</div>

Hello,

is there a way to add a custom validation inside the model ?

like

validates\_passwords\_are\_equal :password, :password\_confirm

that would make sure the password and password\_confirm fields are the  
same ?

thanks  
adam

---

<div class="post-metadata">

**Author:** ![straightflush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@straightflush](https://www.ruby-forum.com/u/straightflush)\
**Post date:** [November 26, 2005, 7:39pm UTC](https://www.ruby-forum.com/t/custom-validation-in-model/48909/2 "2005-11-26T19:39:45Z")

</div>

There’s a validation in the core that does precisely that:  
validates\_confirmation\_of:  
[http://api.rubyonrails.com/classes/ActiveRecord/Validations/](http://api.rubyonrails.com/classes/ActiveRecord/Validations/)  
ClassMethods.html#M000653

for custom validations use validates\_each:  
[http://api.rubyonrails.com/classes/ActiveRecord/Validations/](http://api.rubyonrails.com/classes/ActiveRecord/Validations/)  
ClassMethods.html#M000652

hth,  
Stephen

---

<div class="post-metadata">

**Author:** ![straightflush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@straightflush](https://www.ruby-forum.com/u/straightflush)\
**Post date:** [November 26, 2005, 8:04pm UTC](https://www.ruby-forum.com/t/custom-validation-in-model/48909/3 "2005-11-26T20:04:11Z")

</div>

Check out validates\_confirmation\_of

Kent
