I would use the find command for that, like this:
Code:
find . -maxdepth 1 -type f ! -name "*.txt" -exec rm '{}' +
This will remove everything but files ending with .txt.
Short explanation: Find will look in the current directory (indicated py the parameter "."), withouth looking into subdirectories (-maxdepth 1) for files of the type file (no directories, option -type f) that have not a name that matches to "*.txt" (! -name "*.txt") and after assembling those filenames it will invoke rm to delete them (-exec rm '{}' +).
Looks complicated at first, but once you have grasped the concepts of find you don't want to miss that command.
For more info on find look at