# Reg: regular expression

**URL:** <https://www.ruby-forum.com/t/reg-regular-expression/89401>\
**Category:** Rails\
**Created:** [March 20, 2007, 5:57am UTC](https://www.ruby-forum.com/t/reg-regular-expression/89401 "2007-03-20T05:57:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiva\_98](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@shiva\_98](https://www.ruby-forum.com/u/shiva_98)\
**Post date:** [March 20, 2007, 5:57am UTC](https://www.ruby-forum.com/t/reg-regular-expression/89401/1 "2007-03-20T05:57:43Z")

</div>

how to validate using regular expression using

1.name should be alpha numeric  
2.min 5 characters and max 15  
3.“two alphabets followed by a number” format not allowed in the  
beginning .if any one have solution.pls send me

---

<div class="post-metadata">

**Author:** ![shiva\_98](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@shiva\_98](https://www.ruby-forum.com/u/shiva_98)\
**Post date:** [March 20, 2007, 6:19am UTC](https://www.ruby-forum.com/t/reg-regular-expression/89401/2 "2007-03-20T06:19:54Z")

</div>

> 1.name should be alpha numeric  
> 2.min 5 characters and max 15  
> 3.“two alphabets followed by a number” format not allowed in the  
> beginning .if any one have solution.pls send me

Completely untested. (Straight from brain to keyboard, so you will  
have to debug.) Not sure I understand #3 correctly, but if you _want_  
to match two letters followed by one or more alpha-numerics,  
something like this should work, but again, untested…

validates\_length\_of :whatever, :within =\> 5…15, :on  
=\> :create, :message =\> “must be between 5 and 15 characters long”  
validates\_format\_of :whatever, :with =\> %r{\A[a-zA-Z]{2}\w+  
\Z}, :message =\> “must be blah blah blah.”

Good luck.

Preston

---

<div class="post-metadata">

**Author:** ![shiva\_98](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@shiva\_98](https://www.ruby-forum.com/u/shiva_98)\
**Post date:** [March 20, 2007, 6:37am UTC](https://www.ruby-forum.com/t/reg-regular-expression/89401/3 "2007-03-20T06:37:40Z")

</div>

thans buddy
