Seems Complex validation --- pls help

Hi.. i have a auto complete field for my authority_id field.authority_id field is not mandatory.if the user not fills it will take the default authority id as value. but i want to validate if the user enters invalid authority name into the auto complete text box... i can do this in my controller... but how can i implementd as modal validation. pls help on this below is my controller side implementation #if autority text box is empty? if params[:user_info][:login].empty?               @user = UserInfo.find_by_login('admin')               @company.authority_id = @user.id else      authority = UserInfo.find_by_login(params[:user_info][:login])      if authority.nil?         flash[ :error ] = "*Please Enter valid Authority name"      else          @company.authority_id = authority.id      end end

hi.. some one pls help me... thanks