Search code examples
iphonemobile-website

How to prevent iPhone to interpret "AD 800-1200" as phone numbers?


I am developing a mobile website and on a page there is text such as "AD 800-1200". If I press this text and release, iPhone asked me whether to dial a number.

How to prevent this?

Thanks!


Solution

  • See the following html:

    <html>
    <div id="s2">AD 800&#8232-1200</div>
    <div id="s2">AD 800-1200</div>
    <div id="s2">AD 800 - 1200</div>
    <div id="phone">(800)123-4567</div>
    </html>
    

    The first and third line produce "no phone number", while the second and fourth do. You can see for yourself at http://www.floris.us/SO/phoneme.html

    Note - the "magic number" in the first example is a unicode control character that does not render to the screen - but it does throw the "number parser". With this trick you can have a number that "looks" exactly like a phone number, but doesn't get recognized as such.

    The third example just adds spaces around the hyphen - that seems to work too.

    I can't claim all the credit for this cleverness. I did see https://stackoverflow.com/a/17507409/1967396 ...

    One other thing: you can add the following line to the header of your file:

    <meta name="format-detection" content="telephone=no">
    

    This will turn off telephone number detection. This latter trick can be found at https://stackoverflow.com/a/227238/1967396 - with thanks to Aaron Brager for bringing it to my attention.