The easiest way is to open it as an image and check it's a JPG type when it's open. However, if it isn't then you will get an exception which may not always be catchable.
A safer way is to open the file as a binary stream and check the start and end: JPG files start with the two bytes 0xFF and 0xD8, and end with the two bytes 0xFF and 0xD9. There are also some specific ASCII strings in JPG files:
http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_numbers_in_files[
^]
If these are present, it probably is a JPG. But the only true way to be absolutely sure is to load it as an image!