Such a license would violate Clause 6 of the Open Source Definition (src: http://opensource.org/osd-annotated ), which states that you cannot restrict use based on fields of endeavor. Therefore, you could make the license, but you could not call it open-source.
As an aside, even though it might ruffle some feathers, I don't think it would actually be illegal to do so — right?
Probably not illegal, but whoever does it would be muddying up a term with a clear, established definition.
What if I develop software that allows me to restrict usage of software based on field of endeavour, then I apply an open source license to it?
One license offered for Phil Rogaway's OCB block-cipher mode explicitly prohibits military use. (although, as I read it, the military could use still open source implementations under the other license)