Before iOS 7, the iPhone didn't support blocking texts from spammers, exes and other unwanted contacts. Even apps couldn't perform the job, short of a few tweaks that required jailbreaking. On an updated phone, however, the feature is built into the system, so there's no need to break your warranty or buy a new app -- just pick someone from your messages or contacts to block.
Block an Unfamiliar Number
Open any message from the number you want to block in the Messages app on iOS 8, and tap Details.
Press the i button to see the texter's info page.
Scroll to the bottom of the page, tap Block This Caller and choose Block Contact to confirm.
Block a Contact
Open the Messages section of the Settings app and tap Blocked.
Tap Add New to pick a contact from your contact list. Picking a contact adds all of the contact's phone numbers and email addresses to your blocked list.
Swipe from right to left along any individual entries you want to remove, and press Unblock. You can remove one phone number or email address from the list while leaving the others blocked, even if they all come from the same contact.
Blocking someone's texts also blocks iMessages.
Numbers you block in the Messages app show up on the list in the Settings app, just like blocked contacts.
The iPhone keeps a single block list for messages, calls and FaceTime calls. When you block someone from messaging you, it unavoidably blocks that person from calling you as well. If you remove someone from the blocked caller list, it also removes that person from the blocked messaging list. As a workaround, you can block someone's cell phone but leave a home or office number unblocked.
There's no setting on the iPhone to completely turn off text messaging. If you don't want to send or receive any texts, contact your cell provider and ask to have the feature disabled on your plan.