Create Html/Css Phone Mask

Asked

Viewed 3,568 times

3

It would be like making a mask without plugin in a field of my form ex: (00) 0000-0000 ?

Usand CSS or HTML only?

  • I believe only with javascript (pure) same

  • Ricardo, what would the ninth digit question look like? Anyway, you should use Javascript.

  • I want to include, just quoted an example of formatting, I have an open question trying to use JS: [ http://answall.com/questions/135478/problema-com-m%C3%A1scara-no-form ]

  • Making mascara will take a lot of work of pure javascript and nothing easy can give bug, and I prefer to use jquery calls Masked input already help, and why not try? http://jsfiddle.net/dKRGE/3/

1 answer

11


You can use regular Expression in the tag <input> of Html5.

It will not work as a mask but it will validate the phone in the format (99-99999999) or (99-999999999).

Ex:

<input type="text" required id="partNumber" pattern="^[1-9]{2}\-[2-9][0-9]{7,8}$" />

For your example [(99)9999-9999] the regular Expression would be <input type="text" required id="partNumber" pattern="^\([1-9]{2}\)[0-9]{4}\-[0-9]{4}$" />

See working in https://jsfiddle.net/p9at0ovL/

Note: It will only work in newer browsers.

  • I followed this tutorial that uses the function you mentioned: http://codigofonte.uol.com.br/codigos/mascara-para-phones-de-8-e-9-digitos-jquery

Browser other questions tagged

You are not signed in. Login or sign up in order to post.