If inside anonymous function

so i have a code :

whitelisted_params =
  params
  |> Map.take(
    ~w(id ph_id name address)
  )
  |> Enum.map(fn {k, v} -> {String.to_atom(k), String.replace(v, ~r/[^\w\s\-]/, "")} end)

i’m trying to convert String.replace(v, ~r/[^\w\s\-]/, "") to integer if key is id or ph_id