• First, open Settings. 
  • Scroll down until you find Messages. Tap it.
  • Next, scroll down until you find "Filter Unknown Messages." Turn it on.
  • You’re done. 

Note: After following the above steps, when you go into your messages app, you'll see two tabs at the top of the screen. On the left there’s the  "Contacts & SMS" tab. This tab will contain messages from contacts in your address book -- your known contacts. On the right you’ll see the new "Unknown Senders" tab. Now, if you receive a message from a sender who’s not in your address book, you won't get a notification. Instead, it will be dropped into this tab.