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.
Google Voice gives you, for free, an alternate phone number that you can (selectively) forward to other numbers. They also have a widget you can embed onto a webpage that can be used to call you directly from the page.
If you don't want to go through setting up your own asterisk server and routing SIP through it, there are plenty of VOIP options... Google Voice being one of them. I display my GV number on my website through an image to discourage any sort of web scraping shenanigans.
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.