# File formvalidator.rb, line 645
    def apply_hash_constraint(key, constraint)
      name     = constraint["name"]
      action   = constraint["constraint"]
      params   = constraint["params"]
      res      = false
      skip_end = false

      # In order to call a builtin or proc, params and action must be present.
      if action and params
        arg = params.map {|m| @form[m]}
        if String === action
          res = self.send("match_#{action}".intern, *arg)
        elsif Proc === action
          res = action.call(*arg)
        end
      end

      if Regexp === action
        ### New code to handle multiple elements (beware!)
        if Array(@form[key]).length > 1
          index = 0
          skip_end = true
          Array(@form[key]).each do |value|
            m = action.match(value)
            res = m[0] if m
            if res
              @form[key][index] = res if untaint?(key)
            else
              @form[key].delete_at(index)
              constraint = (name) ? name : constraint
              @invalid_fields[key] ||= []
              unless @invalid_fields[key].include?(constraint)
                @invalid_fields[key].push(constraint) 
              end
              nil
            end
            index += 1
          end
        ### End new code
        else
          m = action.match(@form[key].to_s)
          res = m[0] if m
        end
      end

      if not skip_end
        if res
          @form[key] = res if untaint?(key)
        else
          @form.delete(key)
          constraint = (name) ? name : constraint
          @invalid_fields[key] ||= []
          unless @invalid_fields[key].include?(constraint)
            @invalid_fields[key].push(constraint) 
          end
          nil
        end
      end
    end