How to resolve this? Problem with RichEditor - javascript

It turns out that it limits the characters up to 1500, but when I reach 1500 if I keep writing, one more character is added, leaving the total at 1501.
From what I could verify, the textarea DOES limit up to 1500, but when I show the characters that are being written, there is the error.

Related

Adjust tslint condition for max-length limit

At our workplace, we use tslint to maintain similar code structure.
Our tslint includes rule like this:
"max-line-length": [
true,
120
],
which enforces (gives warning if not followed) to complete a line within 120 characters.
But, many times, with long functions, we have multiple conditions and code goes under tab after tab.
So, the problem is: Even if I start a line from 110th character space and write more than 10 characters, it shows me warning.
Is there anyway, I can change the tslint.json, so that it counts the length from first non-empty character or something like that ?
Thanks in advance.

Is there a way in JavaScript that (10000).toLocaleString("zh") can print out 一萬 or 一万 in Chinese locale?

Perhaps in any browser or any environment such as NodeJS? The closest I can get to is:
console.log((10000).toLocaleString("zh-u-nu-hanidec"))
"一〇,〇〇〇"
inside of Chrome or Firefox. (The result being looked for is 一萬 or 一万, with the first form traditional Chinese character, and the second form simplified Chinese character). I am not sure what the u is for zh-u, maybe it is for unicode and it needs to put in front of nu for number system. Also I wonder why it has to be this form but
(10000).toLocaleString("zh", {numberingSystem: "hanidec"})
would give "10,000".
The first line output really is just converting 1 to 一, which is just a one to one mapping of digit characters. The way 10000 is spoken or written should be 一萬 or 一万. There is a 10000 unit. So for 1000, it is 一千, meaning "One(一) Thousand(千)", but for 10000, it is not written or spoken as "Ten Thousand" but as "One(一) Wàn(萬)", with Wàn meaning 10,000.
I read into MDN and ECMA-402 but can't find the relevant info yet.

Limit lines in a textarea? [duplicate]

This question already has answers here:
Limiting number of lines in textarea
(8 answers)
Closed 6 years ago.
I've got a form that people can fill out and the results of the form are displayed on a page. The form is limited to 2000 characters, however there's nothing limiting how many line breaks there can be, so someone could just put one character per line and get 2000 line breaks, which clutters up the page pretty badly. I'm looking to limit the number of lines that they can type into the textarea so the limits are 2000 characters or 40 lines, whichever comes first.
I would also need this to be protective of people pasting large amounts of text into the form as well. I looked at a lot of other posts about this but none of the answers worked when I tried them. Thanks!
have you specified <textarea maxlength="2000"></textarea> - that would be a good place to start. this would limit the characters to 2000.
You could also check for the enter key (keycode=="13" if i recollect correctly) and either a) disallow it or b) only allow it after a full stop or after e.g. >30 characters. Just a suggestion
Definitely specify the maxlength though. Then no more than that will be able to be inputted. Note that breaks count as characters and are deducted from the characters remaining.
Have a go at this and you will see.
function textCount(val) {
var len = val.value.length;
if (len >= 500) {
val.value = val.value.substring(0, 2000);
$('#amtleft span').text(0);
} else {
$('#amtleft span').text(2000 - len);
}
}
textCount($('#longText').get(0));
$('#longText').keyup(function() {
textCount(this);
});
textarea{height:150px;
width:300px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<textarea id='longText' ></textarea><br>
<span id='amtleft'><label>(<span>2000</span> characters left)</label></span>

Match second number, if the first doesn't exist

I'm working on a regex that needs to remove data that is in a large text. Before running the regex, I replace all spaces, all lines by a single space, so a spreadsheet like this:
Something 50.00 10.00
Other Piece 100,00
Becomes this:
Something 50.00 10.00 Other Piece 100,00
This table in specific, there is 4 columns , number, name, amount of fees and the total amount, this way:
01 Some Name 40,000 10.000
02 Some Name 40,000 10.000
03 Some Name 40,000 10.000
But sometimes, the amount of fees doesn't exist, just the total amount:
01 Some Name 10.000
01 Some Name 40,000 10.000
And i just need catch the total amount, so i'm suffering to find out a regex to catch the 4 value, if the 3 value exists.
That's how long i get:
\b(?:228)\s.*?(?:[a-z]+)\s(?:[\d/.,]+)?\s([\d/.,]+)
This RegExp is capturing the 4 number if the 3 exists, but when the 3 doesn't exist, it won't work. So, i would like to ask for help. How can i make this work?
What i'm trying to do is:
Find a number defined by me, like 228, after that, find the name, which can be one or more, after, catch the 2 value if the 1 value exists, or catch the 1 value if the second doesn't exist.
http://regexr.com/3cq7e
Thanks!!!
Update -
Also, i can't change the process before, so i can't avoid removing the lines, spaces, etc. And i can't use a regex like: find the number defined by me, after that find the name, then find the next name and catch the previous value, cause sometimes the next name may not exists.
Thanks.
Hope this helps:
\b(?:228)\s+(?:[A-Za-z ]+?)\s+(?:[\d]+[.,][\d]+\s+)?([\d]+[.,][\d]+)
This assumes that the names have no special characters or numbers (that they have only A through Z or white space). Another assumption is that the amount of fees and total amount always have either a period or comma and also have digits following the period or comma.
What if you use a regex that supports multiline and search always for the last decimal number ? This way you will get either the 4th or the 3rd numbers, whatever exists.
(\d+\.?\d+)$/gm
Play with it here.

Can i generate unique text 1 lacs time in javascript through any method who does not need any framework?

i have a word from A to Z. all word should in small latter (Capital not include) and 1 to 9 (included all special word who can be used in email address (just for a test)).
how i can generate unique 1 lacs text who never repeat itself. can anyone solve this puzzle.
i want a another thing that all words should not more then 10 char and not should minimum 6 char long
Put the characters in an array. Copy the array as the source of a new line. Randomly slice words from the array and put them in the line (use Math.random() * array.length | 0). Keep going for the required number of words.
You can also just use a string and charAt(index) if you only want single characters, but you have to keep cutting out the character that you select which is likely less efficient than using array.slice.
Whatever suits though, since performance is likely irrelevant.

Categories

Resources