It's also illegal in the NCAA unless the player catches the ball.
This is copy/pasted from the NCAA rule book on this question:
SECTION 4. Batting and Kicking
Batting a Loose Ball—ARTICLE 1
Approved Ruling 9-4-1
I. Team A attempts a field goal from Team B’s 30-yard line. A Team
B player in the end zone leaps above the crossbar and bats the ball
in flight. The ball goes out of bounds in the end zone.
RULING:
Foul for batting the ball in the end zone. During regulation play,
postscrimmage kick enforcement gives a safety by penalty. In extra
periods, enforcement of the 15-yard penalty is at the previous spot
and Team A retains possession.
II. Team A attempts a field goal from Team B’s 30-yard line. A Team B
player in the end zone leaps above the crossbar and bats the ball in
flight. The ball goes into the end zone and is recovered by Team A.
RULING: Foul for batting the ball in the end zone. The result of the
play is a touchdown.
III. Team A attempts a field goal from Team B’s 30-yard line. A Team B
player in the end zone leaps above the crossbar and bats the ball in
flight. The ball goes into the end zone and is recovered by Team B.
RULING: Foul for batting the ball in the end zone. The result of the
play is a touchback, safety.
IV. Team A attempts a field goal from Team B’s 30-yard line. A Team B
player in the end zone leaps above the crossbar and bats the ball in
flight. The ball goes into the field of play.
RULING: Foul for batting
the ball in the end zone. During regulation play, postscrimmage kick
enforcement gives a safety by penalty. The ball remains alive, and
Team A may elect the result of the play. If Team A recovers, does not
score and accepts the penalty, or if the play occurs in an extra period,
enforcement is at the previous spot.
V. Team A attempts a place kick on the try. A Team B player in the end
zone leaps above the crossbar and bats the ball in flight. The ball goes
out of bounds in the end zone.
RULING: Foul for batting the ball
in the end zone. Penalty—Half the distance from the previous spot.
Postscrimmage kick rules do not apply on the try (Rule 10-2-3).
VI. Team A attempts a place kick on the try. A Team B player in the end
zone leaps above the crossbar and bats the ball in flight. The ball goes into the end zone and is recovered by Team A.
RULING: Foul
for batting the ball in the end zone. Team A may decline the penalty
and scores two points.
VII. Team A attempts a field goal, and B23, in the end zone, goes above
the crossbar and catches the ball.
RULING: Legal play.