How to check the number of function arguments given by the user

You can redefine your function f to accept a variable number of arguments (x__) and then check the length with Length.

Clear(f);
f::argerr = "Two arguments expected, but `1` given.";
f(x__) := 
  If(Length@List@x == 2, List@x, 
   Message(f::argerr, Length@List@x); $Failed);

f(1, 2)
(* {1, 2} *)

f(1, 2, 3)
(* f::argerr: Two arguments expected, but 3 given. *)
(* $Failed *)

Another, probably a more appropriate way, as suggested in the comment by Jason, is to use CheckArguments.

Clear(f);
f(x_, y_) := {x, y};
f(args___) := Null /; CheckArguments(f(args), 2)

f(1, 2)
(* {1, 2} *)

f(1, 2, 3)
(* f::argrx: f called with 3 arguments; 2 arguments are expected. *)
(* f(1, 2, 3) *)