2

I have a basic form input, <input>. I'd like to make it look nice and neat for phone number entry and tax Id entry. Phone number could be anything like:

xxx.xxx.xxxx

xxx-xxx-xxxx

(xxx) xxx-xxxx

TaxId could include

xxx-xx-xxxx

xx-xxxxxxx

I really don't care which format it is as long as there is a format when someone types in the input box and that the input box will accept nothing but numbers.

Finally, and this is where I've run into trouble, I need to bind the input to ng-model.

I've tried several different plugins but either I don't know how to implement them or I can't bind them to ng-model.

This one seemed most promising but it its binding to ng-model is inconsistent at best and generally seems not to work: https://github.com/mareczek/international-phone-number

<input international-phone-number only-countries="us" type="tel" placeholder="Phone Number" ng-model="user.phone">

When I first did this it seemed that the number was attaching to ng-model but upon further review ng-model in this input remains undefined after inputting a phone number.

It seems like there should be a really simple way to get this done.

TylerH
  • 20,799
  • 66
  • 75
  • 101
rashadb
  • 2,515
  • 4
  • 32
  • 57
  • What is your question? If you are asking for resources to use, those questions are off topic. Otherwise you should show what you tried because what you have now is far too broad – charlietfl Aug 25 '15 at 14:04
  • @charlietfl within the input box I want the number to be formatted as described above but I also want the raw number to be attached to ng-model. I will add what seemed to work best to the question. – rashadb Aug 25 '15 at 14:07

1 Answers1

1

Filter

You could use UI Utils mask It allows you to define an allowd input format and will handle the validation for you as well as the formatting. here

source for ans here please credit the owner

Community
  • 1
  • 1
Joe Lloyd
  • 19,471
  • 7
  • 53
  • 81