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

JavaScript

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
stargateatlantis

ASKER
So how come you can't execute it like this

var myNumber=1111111111;

console.log(myNumber.toPhone);
leakim971

Add parentheses :
var myNumber=1111111111;

console.log(myNumber.toPhone());

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy