I have a list of phone numbers in different formats like '1234567-8901', '49123456 6544', '861234567899', and lots of other formats also. I want to format the phone number in the format like for example lets take USA phone number, it should display like '+ 1 xxx-xxx-xxxx'. We are using thymeleaf and js for implementing this.Please tell me the step by step process on how to implement this?
You can use regex to solve this. I would suggest taking a look at this stack overflow answer https://stackoverflow.com/a/8358141/19184713
Related
I'm using Spring MVC and dojo in my project.
We need to have an input for phone number by given format like: (###) ###-####
The phone number should automatically format as it's being typed.
The validation should be inside the text field it self with placeholder per each digit separated by '-'.
I tried to look over the web for an exist solution but I couldn't find any.
Can you try this library for phone number format?
https://www.npmjs.com/package/libphonenumber-js
I am working on JavaScript program which gets as input string and should return JSON or any other form with organized currency parts.
For example: func("2 kEURO") should return {value:2, scalar:"thousand", currency:"EURO"}. I have list of currency and scalar symbols but I would like to correctly read "from 2k to 5k USD" as well. I am using now js parser and it is enough for simple sentences.
I would like to ask if you know any others methods to make it done? I have been looking but what I found was only parsers with regex. It would be awesome if I could also read "5k in USD, 4k in EURO" any ideas?
Kind regards.
In my ASP.Net web application, I allow the user to enter a value for the weight of a product. The user can be anywhere in the world (I have users from the US, France, GB, China, etc).
They enter the weight in a number of ways, including:
Using 100000.99 as an example
100,000.99
100 000,99
100'000.99
You see where I am going with this. I am looking for a way to 'cleanse' this input, and format it in such a way that it will be (forgive my ignorance) 'normal'.
Any ideas on how to do this? Or frameworks?
Thanks in advance!
I recommend to use UI decorators and validators to allow user of each culture input and see numbers formatted for his culture. Then you would able to know which culture is used and handle it correctly. Also you should allow user to select another culture in case you detect it incorrectly.
Please see this link to see how to determine user culture and language
I have a number being returned from a database with an associated format string. For the purposes of this example think 2 columns.
Value FormatString ----> DESIRED OUTPUT FROM JAVASCRIPT/JQUERY
----- ------------ -------------------------------------
100 #0.00 100.00
100000 #0,.0K 100.0K
.193 #0.0% 19.3%
Formatting options include # of decimal points, thousands separator or not, magnitude (K,M,B), percent, currency, etc. The format strings work just fine in C# and VBA (and I believe Java uses the same format strings).
I am looking for a javascript way (using whatever library is applicable, jQuery preferred) to provide the raw value and the format string and have it return a formatted number.
We are trying to re-write an app and this is what the database is giving us...can't change the database (and not sure I would want to either as the database shouldn't care about formatting the numbers for display).
Worst case: we have to change all the format strings to something javascript likes...but even then I have yet to find a usable solution that accepts a format string.
EDIT
I have looked into the following libraries/plugins/tools.
Numeral.js
DecimalFormat.js
jquery-numberformatter
All have varying levels of "correctness" (as it applies to the C#/VBA format strings). I could probably hack something together using 1 of the above as a starting point but want to see if there is something already out there.
Numeral.js feels like the most promising but it doesn't handle magnitude the way I need (it wants to auto determine the magnitude for you based on the value passed in). This feels like the "easiest" one to alter if that is the ultimate solution.
And after sleeping on it and trying to google again the morning I believe I have found what I need.
flexible-js
This appears to be working as I would expect. Don't know if it handles every use case perfectly but based on initial testing it looks to be working as I need.
This is a long-shot and I'm writing because I have not idea where to start.
I want to write some code that can automatically and on regular basis grab the 5 dates from this website and put them into my iCal calender.
Where should I start and end to do this?
I'm pretty good in RoR and Javascript, but have absolutely no idea what technology I should use to accomplish this.
Hope you can shed some light on my question.
Thanks
Assuming the HTML page is always going to keep the same basic structure, you could use something like nokogiri to locate the nodes containing the dates.
You can then use the Date.strptime or DateTime.strptime methods to convert the date from the particular format, into a Date or DateTime object, as required.
As for then adding the dates to your calendar, it's not something I have had to do, but you might want to check out How to interact with a CalDAV server from Ruby?
Use an XMLHttpRequest object in Javascript to download the page that you need and then use a regular expression to parse out the dates. It seems that the dates all have a fixed format:
<b>Mon Day Hr:Min UTC+4</b>
so it should be easy to write the regular expression for this. I don't know the exact Javascript Regex format but here's the .NET equivalent, it should be easy to tweak this to Javascript - hope this helps:
<b>(?<date>(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2} [0-9]{2}:[0-9]{2}) UTC[+-][0-9]+</b>
This finds all date fields in the page - once you have the date fields, each Regex match will have a sub-group named date that contains the actual date part.
If you go to this page: .NET Regex tester you can test the above expression to see how it returns the dates - just copy & paste your page's source with the dates. As I said, this is for .NET, not for Javascript but the differences are not terribly big.
Use a Ruby script. The Mechanize gem can scrape the dates from the web page. Then the ri_cal gem can add them to your calendar. A pure JavaScript approach like xxbbcc suggested may be possible but it will almost certainly be more involved. If you're already familiar with Ruby, I'd recommend taking advantage of the "magic" and let these gems do the dirty work for you.