admin commited on
Commit
c38c77c
Β·
1 Parent(s): 6b6a477

add word count

Browse files
Files changed (2) hide show
  1. index.html +2 -1
  2. js/main.js +7 -1
index.html CHANGED
@@ -23,7 +23,8 @@
23
  <div id="Tab2" class="tabcontent">
24
  <h1>String β†’ Length</h1>
25
  <textarea rows="14"></textarea>
26
- Length : <text>0</text>
 
27
  </div>
28
  <div id="Tab3" class="tabcontent">
29
  <h1>Plaintext β†’ MD5</h1>
 
23
  <div id="Tab2" class="tabcontent">
24
  <h1>String β†’ Length</h1>
25
  <textarea rows="14"></textarea>
26
+ String Len : <text id="len">0</text><br>
27
+ Word Count : <text id="words">0</text>
28
  </div>
29
  <div id="Tab3" class="tabcontent">
30
  <h1>Plaintext β†’ MD5</h1>
js/main.js CHANGED
@@ -42,6 +42,11 @@ function toBase64() {
42
  };
43
  }
44
 
 
 
 
 
 
45
  $(function () {
46
  toBase64();
47
 
@@ -53,7 +58,8 @@ $(function () {
53
  });
54
 
55
  $('textarea').bind('input propertychange', function () {
56
- $('text').text($(this).val().length);
 
57
  });
58
  $('text').click(function () {
59
  clipbd($(this).text());
 
42
  };
43
  }
44
 
45
+ function countWords(text) {
46
+ const words = text.match(/[a-zA-Z0-9_]+/g) || [];
47
+ return words.length;
48
+ }
49
+
50
  $(function () {
51
  toBase64();
52
 
 
58
  });
59
 
60
  $('textarea').bind('input propertychange', function () {
61
+ $('#len').text($(this).val().length);
62
+ $('#words').text(countWords($(this).val()));
63
  });
64
  $('text').click(function () {
65
  clipbd($(this).text());