Richard, if you can secure the box to the stud you have it made. There is no specific criteria I know of beyond
Quote
The metallic outlet or switch boxes shall be securely fastened to the studs

Good luck

Roger