If I display my email address on my website, I would probably receive a lot of spam, so I can set up a contact form instead. If I want to display my phone number, how can I prevent unwanted phone calls?
Well, the first thing is not to worry about it so much, because your threat model is unlikely.
Voice spammers don't get phone numbers by sending bots out to crawl the web, because they have much better sources of numbers.
And targeted attacks, where someone wants to prank call you specifically, can't be prevented because you can't tell who is an attacker and who is a customer.
If you still want to obscure your text, then here you can use similar techniques to those used to obscure email addresses:
- Do the formatting weird so bots don't recognise it as a phone number.
- Use an image of the number instead of the text. (But please don't do this, because it'll break accessibility.)
- Shrug your shoulders and put good anti-spam in place.
If you are in the US or Canada, you could use Google Voice (or any other VOIP service) and supply the Google Voice number. Google has pretty good anti-spam features built in to Voice and you can block any numbers that are problematic or only allow it to forward to your phone at certain hours.
You can use the same methods that are used for e-mail adresses:
- Replace with image (bad for accessibility)
- Require ReCaptcha to show (inconvenient)
- Make hard to detect by inserting hidden text between the individual numbers
In addition to this, you can replace zeros with uppercase o's, however some scrapers can handle this (note that the scrapers I'm talking about are not used by spammers).
Honestly, I doubt phone spammers scrape web sites for numbers, much easier to simply dial all numbers and detect which ones exist.