# How to validate\_uniqueness\_of the joint of two attributes?

**URL:** <https://www.ruby-forum.com/t/how-to-validate-uniqueness-of-the-joint-of-two-attributes/175106>\
**Category:** Rails\
**Created:** [September 8, 2009, 6:32am UTC](https://www.ruby-forum.com/t/how-to-validate-uniqueness-of-the-joint-of-two-attributes/175106 "2009-09-08T06:32:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anh\_Hung\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@Anh\_Hung\_N](https://www.ruby-forum.com/u/Anh_Hung_N)\
**Post date:** [September 8, 2009, 6:32am UTC](https://www.ruby-forum.com/t/how-to-validate-uniqueness-of-the-joint-of-two-attributes/175106/1 "2009-09-08T06:32:06Z")

</div>

Hi,

I have a form that asks users to put in their :first\_name and  
:last\_name.  
How do I validate that their full\_name (first\_name + last\_name) is  
unique?

Thanks!

Nguyen Anh Hung  
Assistant Project Manager/ Consultant/ Business Analyst  
Tech Propulsion Labs  
Mobile: +84987 005 477  
Twitter: [http://www.twitter.com/anhhung](http://www.twitter.com/anhhung)  
Blog: [http://www.fresco20.com](http://www.fresco20.com)  
Skype: anhhung.n | Yahoo: hero.tuxer | Gtalk: anhhung

---

<div class="post-metadata">

**Author:** ![Anh\_Hung\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@Anh\_Hung\_N](https://www.ruby-forum.com/u/Anh_Hung_N)\
**Post date:** [September 8, 2009, 9:17am UTC](https://www.ruby-forum.com/t/how-to-validate-uniqueness-of-the-joint-of-two-attributes/175106/2 "2009-09-08T09:17:12Z")

</div>

You can use :scope  
validates\_uniqueness\_of :first\_name, :scope =\> :last\_name  
If your database is huge, indexing last\_name will help. Read more here:  
[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html)

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)

On Tue, Sep 8, 2009 at 9:59 AM, Anh Hung N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> I have a form that asks users to put in their :first\_name and :last\_name.  
> How do I validate that their full\_name (first\_name + last\_name) is  
> unique?
