How can we format a telephone number using Javascript - javascript

Can anyone let me know how can I format a telephone number automatically using javascript.
I have seen some of the code samples in the internet....But my point is not all the countries have the country code just 3 numbers.....and moreover if someone write the country code 0091 and the number will be like 9878...... Then the codes I have seen in the internet formats them like (009)-(19878...) . If u see the country code will be taken wrong ......
Can someone clear out this
Thanks

Try to look at libphonenumber:
http://code.google.com/p/libphonenumber/

Related

How to format currency while typing, but you also want to use that input as a number after formatting (jQuery/Javascript)

I am trying to build an online calculator and I wanted to format my input into currency while typing.
On this website: https://www.ratehub.ca/cmhc-mortgage-insurance the asking price input box is similar to what I would like to achieve.
I have tried this code here:
$("#formattedNumberField").on('keyup', function(){
var n = parseInt($(this).val().replace(/\D/g,''),10);
$(this).val(n.toLocaleString());
//do something else as per updated question
myFunc(); //call another function too
});
But it would display NaN after typing a number and deleting it, also I can not use the formatted number for future calculation.
Any help would be appreciated!

formating UK mobile to international number with Zapier Code Javascript function

The scenario is...
A visitor comes to my landing page and completed the form, which included a telephone number.
Using Zapier I then pass that form data to ActiveCampaign.com using a "ZAP".
However as ActiveCampaign is in USA, they require the phone number formatting to international standard, instead of local UK.
Most numbers in UK are 07788990022
But it needs to be presented as +447788990022
So I need to use this built in function of Zapier listed below
https://zapier.com/help/code/
And need some Javascript code writing that will check the number
Is it valid UK mobile number? I.e. 11 digits
Remove all spaces, and trim
If 2nd character is a 7 then replace 1st character (which should be a 0) with +44
I really dont have any idea how to do this! I was hoping for a built in function on Zapier, but apparently not. Any ideas would be awesome!!!
David here, from the Zapier Platform team.
This seems like a pretty straightforward js question! This will be pretty "dumb" validation, but will work assuming the input is correct.
You'll have a code (javascript) step and set the input to be phone: input from step 1. Your code will look like this:
var ph = inputData.phone.replace(/\s+/g, '') // remove all whitespace from string
if (ph.length !== 11) {
// invalid phone number. do nothing?
return []
}
if (ph[1] === '7') {
ph = '+44' + ph.substr(1)
}
return {formattedNumber: ph}

Javascript currency divider

Actually my problem is very easy but I didnt make it
So my inputs are like that: 165.000,00$ and my diveder 1.5 and result expected 110.000,00$ but when I try it comes 110,00 how can I show like that 110.000,00 (we can ignore symbol)
It looks like you're just having a problem with it not adding the two decimal points afterwards, right? You'd probably be looking for something like this: How can I format numbers as money in JavaScript?

d3.format wont keep trailing zero

I'm using d3.round(num,2) to round a number from say, 2.567 to 2.57. My problem is that when I do this, I want 2 decimal numbers of precision to be used at all times/regardless of if it is a zero.
when I have a number like 2.201, I want the display to be 2.20, and instead am coming up with 2.2. Is there any way to format the round function to always include zeroes?
Thanks for any help!
Edit: used num.toFixed(2) and that works, but I am returning d3.format("$")(num.toFixed(2)) and that is only returning $2.3, which is the reason I needed this, I am looking to display a price. If anyone has help to offer with that, it would be great, thank you
Try this:
d3.format("$.3n")(num);

formatcurrency Phonegap

Team, I'm trying to format a string of characters into Italian Currency format - say something like €1.230,32 from the api documentation i understand it can be achieved through Worklight - Corodova. But I'm not able to land in a clear - cut example as to how. Can you help ?
Your question is not very clear to me.
If what you actually want to do is to convert a sum of money from one currency to another, you can check the following:
http://docs.phonegap.com/en/2.2.0/cordova_globalization_globalization.md.html
https://github.com/apache/cordova-plugin-globalization/blob/master/docs/globalization.getCurrencyPattern.md
http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/index.jsp?topic=%2Fcom.ibm.worklight.help.doc%2Fdev%2Fc_globalization_in_ibm_worklight.html
http://www.sitepoint.com/build-a-currency-converter-with-jquery-mobile-and-cordova-part-4/

Categories

Resources