Irregular period

If your period is irregular when should you take a pregnancy test while having unprotected sex ?