I don't think there's anything illegal about it.
But for some reason airlines really hate the idea, and will normally fire you when they find out (both of them). They will find out from PRIA or other background checks. You might get lucky and they won't notice.
Also most airlines actually terminate your employment after you last flight, regardless of where that falls within the two weeks.