Link to home
Create AccountLog in
Avatar of stargateatlantis
stargateatlantis

asked on

Trying to convert this into prototype to format Number into phone number

Having problems getting this prototype function to work to format a number into a phone number format.

Number.prototype.toPhone = function () {
    myStr=this.toString().replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
    return myStr
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of stargateatlantis
stargateatlantis

ASKER

So how come you can't execute it like this

var myNumber=1111111111;

console.log(myNumber.toPhone);
Add parentheses :
var myNumber=1111111111;

console.log(myNumber.toPhone());

Open in new window