japanese keyboard format number commas duplicate - javascript

keyboard format number commas duplicate
I have a problem when use JS formatting input number comma with the Japanese keyboard on IOSjapanese
I used: numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ',') to format a number with commas as thousands of separators.
everything worked fine except when I tested with the Japanese keyboard on the IOS environment returned duplicate.
I found the problem because I use String. prototype.replace(). It returns right value. but when I use this vue with numStr.replace(/\B(?=(\d{3})+(?!\d))/g, ','). It returns incorrectly.
I have no idea what is the problem...
Thank you for being so helpful.

Related

RegExp - Using the dollar sign to differentiate hex from decimal [duplicate]

I want to find "U.S.A." (without the quotes) if it is in a string as a whole word.
So good strings should be
U.S.A.
u.s.a.
U.S.A. is a great country
Is this U.S.A. ?
Bad string is
U.S.A.mnop
U.S.A
I tried using
/\bU\.S\.A\.\b/i
But strangely the one that works is - (But it fails for other countries and so not useful)
/\bU\.S\.A\.\B/i
This seems opposite of my understanding from documentation and have searched this and there are lots of similar problems but none of them helped me understand the issue. I think that the last "." is being consumed by \b and hence not working but am still confused.
Can someone please help with explanation and the right search string ? It should also do proper word search of other strings without special characters.
You can check for the word boundary first (as you were doing), but the tricky part is at the end where you can't use the word boundary because of the .. However, you can check for a whitespace character at the end instead:
/\b(u\.s\.a\.)(?:\s|$)/gi
Check out the Regex101

How to handle edge case while trying to grab all digits including decimal between two chars using regex

I am parsing a series of strings with various formats. The last edge case encountered has me stumped. I'm not a great regexer, believe me it was a challenge to get to this point.
Here are critical snippets from the strings I'm trying to parse. The second example is the current edge case I'm stuck on.
LBP824NW2-58.07789x43.0-207C72
LBP824WW1-77.6875 in. x 3.00 in. 24VDC
I am trying to grab all of the digits (including the decimal) that make up the width part of the dimension in the string (this would be the first number in the dimension). What works in every other case has been grabbing all digits from the "-" to the "x" using the following expression:
/-(\d+\.?\d+?)x\B/
However, this does not handle the cases that have inches included in the dimension. I thought about using "look-aheads" or "look-behinds", but I got confused. Any suggestions would be appreciated.
RegEx can be told to look for "zero or one" of things, using (...)? syntax, so if your pattern already works but it gets confused by a new pattern that simply has "more string data embedded in what is otherwise the same pattern" you can add in zero-or-one checks and you should be good to go.
In this case, putting something like (\s*in\.?\s*)? in a few tactical places to either match "any number of spaces (including none) followed by in followed by an optional full stop followed by any number of spaces (including none)" or nothing should work.
That said, "I cannot change the formatting" is almost never an argument, because while you can't change the formatting, you can almost always change what parses it. RegEx might be adequate, but some code that checks for what kind of general patter it is, and then calls the appropriate function for tokenizing and inspecting that specific string pattern should be quite possible. Unless you've been hired to literally update some predefined CLi script that has a grep in it and you're not allowed to touch anything except for the pattern...
This is the working solution using regex: -(\d+\.?\d+?)(\s*in\.?\s*|x)

How do i Prevent CKEditor convert hexadecimal character to decimal character?

I'm working in CKEditor a few weeks ago.I face some issues now.
CKEditor automatically converts the hexadecimal character to decimal character.
This is the Hexa char I gave t
o the editor.
–
What CKEditor converts.
&
How do I prevent this conversion.
Please, anybody help me to solve this issue.
You may use config.entities_additional like:
config.entities_additional = '#x2013';
to tell CKEditor that this entity could be used inside the editor (so it won't get converted).

using unicode symbols in ngOption <select>

Hello I've ran into an issue that is stumping me:
So I have an ngOption that loops through and displays unicode symbols
<select class="form-control symbolSelect" ng-model="input.loadSymbol" ng-options="d as d.TagShpUTF for d in loadSymbols" ng-change=""></select>
Here is an example jsFiddle showing it working: http://jsfiddle.net/tjm9a6o2/
I set up the datasource to have a unicode character like so: loadsymbols[0].TagShpUTF = '\u2660'
This all works fine as static data, but when I try to pull the data from my DB it displays it as regular text and doesn't seem to know it's special unicode characters.
This is how I have it setup in the DB (Don't mind other columns, TagShpUTF is the important one):
...what I think it's doing is automatically add a second slash '\' so it can be a valid string, but I don't want that to happen. I want it to be recognized as unicode so it shows the symbols in my dropdown (like jsFiddle), but instead it's showing the actual text (like '\u2660').
Any suggestions would be very helpful. Really need a way of storing these symbols and loading them into a drop down. I tried HTML unicode symbols, but they were giving me even more problems than this method. Thanks!
Eureka!!!
So after many painful attempts and exhausting the kind help from #OrGuz, I kind of gave up on using the \u version of unicode and started looking at HTML-Code version again.
I stumbled upon this SO post buried in the garbage i've been digging through. It had a link to a MDN page about String.fromCharCode()
By storing the HTML- Code number in my DB and calling String.fromCharCode()
I was able to load the symbol in the drop down.
spade: HTML-Code= ♣
TagShpUTF= 9827
String.fromCharCode(TagShpUTF); <---- Works!

I want to strip certain characters from a textarea - PHP/Javascript [duplicate]

This question already has answers here:
How to replace Microsoft-encoded quotes in PHP
(6 answers)
Closed 9 years ago.
The Details
I have a simple textarea <textarea></textarea>
The value of this textarea is sent through ajax and stored in a database.
The value in this database is viewed on an iPad (or iPad mini or iPhone, etc)
The Problem
When someone copies text from somewhere (could be anywhere from the internet potentially), I want to remove any weird characters such as: “windows-1252 quotes” from the text before storing them in a utf8_unicode_ci column in a database. This column stores the above quotes but are unknown on certain devices (like iPad)
The Question
How can I remove these characters in Javascript or PHP?
string.replace has been tried from various examples to remove these characters.
htmlentities($sample) has been tried in order to convert these characters but still no luck.
Any help would be appreciated! Thanks!
Regular expressions will do this; php's function for this is preg_replace, javascript's is simply .replace(). You can find usage snippets everywhere ;)
There are two ways to approach this using regex:
1. Define an allowed character range and strip anything that isn't in that range.
[^\w-=+()!##$%^*(] will match NOT anything in this character range (the ^ at the beginning of the character class denotes this). You can then take the resulting matched characters and replace with an empty string.
Working example: http://regex101.com/r/zK2qW6
2. Define a non-allowed character range and strip anything that is in that range.
[“”] will match anything in this character range. You can then take the resulting matched characters, and again replace with an empty string. You could also use a regex unicode range here too.
Working example: http://regex101.com/r/yG4qJ4
In the end, you should choose the path which requires the smallest expression. If there's only a handful of characters to replace, use option #2. If you only want to allow a handful of characters, use option #1.

Categories