You don't have to erase your iPhone or iPad if you forgot its new passcode—provided you act quickly.
There's no worse feeling than forgetting your iPhone's passcode shortly after changing it. Apple understands this, which is why it gives users a brief period to reset a new passcode with the old one to avoid being locked out completely.