Exclusive

Corey Feldman allegedly tried to bring a Taser on an airplane in New York ... and he almost got arrested.

Sources close to "The Goonies" star tell TMZ ... Corey was detained Thursday at LaGuardia Airport, after going through a security checkpoint with a Taser.

We're told Corey always travels with a Taser ... which he normally puts in his checked luggage. He's taken it to England and Canada with no issues, but didn't remember he had it on him until it was too late.

Our sources say when Corey went through security, TSA swooped in and detained him. Newsflash for Corey, it's illegal to have a Taser in your carry-on.

Corey was in New York promoting his upcoming documentary, and after a visit to XM Radio HQ, he and his wife headed for LaGuardia.

The mix up proved costly for Corey, even though he wasn't arrested. We're told he had to buy some luggage to pack the Taser and check it, but he missed his flight.