I would think that would be illegal.
You're right, it is. The rules states that the ball has to enter the basket from above the rim. What PerryJ described is a violation and the ball is awarded out of bounds to the opposing team.
Here's a better explanation:
The NCAA and FIBA see it as a violation.
--------------------------------------------------------------------------------
This is addressed for the FIBA in its rule book under "THE GAME": Rule 1, Article 16, 2.4
RULE ONE – THE GAME
Art. 16 Goal: When made and its value
16.2.4 If a player causes the entire ball to pass through the basket from below, it is a violation.
The FIBA's definition and handling of violations.
RULE FIVE - VIOLATIONS
Art. 22 Violations
22.1 Definition - A violation is an infraction of the rules.
22.2 Penalty - The ball shall be awarded to the opponents for a throw-in at the place nearest to the infraction
--------------------------------------------------------------------------------
This is addressed for the NCAA in its rule book under "VIOLATIONS AND PENALTIES": Rule 9, Section 6
RULE 9 - VIOLATIONS AND PENALTIES
Section 6. Travel, Kick, Fist, Through Basket from Below
A player shall not travel or run with the ball, intentionally kick it, strike it with the fist or cause it to pass through the basket and enter the cylinder from below.
--------------------------------------------------------------------------------
This is addressed for the NBA in its rule book under "PUTTING BALL IN PLAY - LIVE/DEAD BALL": Rule 6, Section I, e(2).