rails validates format with

I want to dynamically validate my password with validates_format_of .

validates_format_of :password,:with => need to get regular expression
dynamically based up on the object setting.

class Admin < AR::Base

validates_format_of :password,:with => lambda {|admin|

def get_regular_exp
self.advanced? ? /^[a-z]/ : /^[A-Z]/


when I run the application I am getting this error :

validates_format_of': A regular expression must be supplied as the :with
option of the configuration hash

I can still use this approach
validate :admin_password

But my client is very particular on using Rails default methods.

Is there any way to solve this issue.


Hi Venkat,

Can you share exact code what have you written in model ?