On an iPhone, open the spam text > tap on the number > choose Block this Caller and tap Block Contact. This won't always work though as spammers seem to be using a different number each time but it's a safe practice to start. If you get frequent spam from the same phone number, you can go into your message settings to block them. According to software security company Norton, replying to spammers lets them know that your phone number is valid thus you could get more spam messages in the future.
As tempting as it is to reply to these numbers to tell them to stop, it's a safer practice not to.