Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a onInput pretty phone number #2

Closed
Natim opened this issue Apr 26, 2020 · 3 comments
Closed

Add a onInput pretty phone number #2

Natim opened this issue Apr 26, 2020 · 3 comments

Comments

@Natim
Copy link
Contributor

Natim commented Apr 26, 2020

/* Handle nice phone number formatting */
function prettifyPhoneNumber() {
  var $phone = $(this)

  var phone = $phone.val()

  phone = phone.replace(/[^0-9]/g, '') // Only keep digits
  phone = (function addSpaces(phone) {
    if (phone.length <= 2) {
      return phone
    }
    return phone.substring(0, 2) + ' ' + addSpaces(phone.substring(2))
  }(phone))

  $phone.val(phone)
}
@Natim
Copy link
Contributor Author

Natim commented Apr 26, 2020

$('#phone').on('input', prettifyPhoneNumber)

@indatwood
Copy link
Collaborator

One of the goals of this project is to rely the less possible on javascript, so I'm not sure we want to do this?

@indatwood
Copy link
Collaborator

I've implemented it nevertheless, let's define the goals for this project together, rather than relying on decisions we didn't do :-) Thanks for the code and suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants