I have a textarea that holds multiple values(ng-model = array with many positions). And Input(text) for single values(one position array).
I am trying to create a directive(one directive both for the input and the textarea) that allows only to type a value if following pattern is respected:
Allowed characters: numbers, dots, Ee & -
Only one dot and Ee per value
value can not start/end with Ee or dots
a value can start but not end with minus(-)
Consecutive dots, minus or Ee are not allowed
Allowed characters: numbers, dots, Ee & -
Max 2 minus(-) symbols if separated by Ee
Minus symbol can only be at the beginning of a value or right after Ee
As I build the directive its getting dirtier so I am hoping that someone shows me a proper way of doing this.
This is what I have so far but many of the rules I wanna apply are not respected like many(-) symbols consecutive, multiple e in the values etc...
Template multivalue textarea:
<script type="text/ng-template" id="form_field_float">
<textarea only-flo class="form-control" rows="{{dbo.attributes[attobj.name].length + 2}}" ng-model="dbo.attributes[attobj.name]" ng-list="
" ng-trim="false" ng-change="dbo._isDirty = true"></textarea>
</script>
Template single value input:
<script type="text/ng-template" id="form_field_float_single">
<div ng-class="{ 'has-error' : theForm.{{ attobj.name }}_{{ dbo._id['value'] }}_{{ dbo.clazz }}.$invalid && !{{ attobj.name }}_{{ dbo._id['value'] }}_{{ dbo.clazz }}.$pristine }">
<input only-flo type="text" class="form-control" ng-model="dbo.attributes[attobj.name][0]" ng-change="dbo._isDirty = true; forceArray(dbo, attobj);" name="{{ attobj.name }}_{{ dbo._id['value'] }}_{{ dbo.clazz }}" >
</div>
</script>
Directive:
app.directive('onlyFlo', function () {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel) return;
ngModel.$parsers.unshift(function (inputValue) {
//var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' ' || s == '.'); }).join('');
var digits= inputValue.replace(/\.{2,}/g, '.').replace(/e{2,}/gmi, 'e').replace(/[^0-9\.\n\r\-e]/gmi, '');
//var digits= inputValue.split(/\s/).filter(function(s){return isNaN(s) ? false : s}).join('\r');
console.log('digits: ' + digits);
var x = String(digits).split("\n");
console.log(x);
for (var i=0; i< x.length; i++){
if (String(x[i]).indexOf(".") !== -1){
console.log('#1 : '+x[i]);
var pos= String(x[i]).indexOf(".");
console.log('pos: ' +pos);
if (String(x[i]).indexOf(".", pos+1) !== -1){
console.log('#2 : '+x[i]);
var pos2= String(x[i]).indexOf(".", pos+1);
console.log('pos2: ' +pos2);
console.log('number before dot delete: ' + x[i]);
x[i].slice(pos2, pos2+1);
x[i] = String(x[i]).slice(0, pos2) + String(x[i].slice(pos2+1, x[i].length +1));
console.log('number after dot delete: ' + x[i]);
}
}
}
digits= x.join("\n");
console.log('digits: ' + digits);
ngModel.$setViewValue(digits);
//the one above (setView...) works better avoids the illegal character to appear on double press
//ngModel.$viewValue = digits;
ngModel.$render();
return digits;
});
}
};
});
Right now what the directive does is:
1 - Replace consecutive dots with one dot. Same with E or e
2 - Remove anything that is not 0-9, -, "\n", "\r", E or e.
3 - Not allow a second dot(a second none consecutive dot)
Obviously this is getting worse as I continue.
I would like a solution that doesn't alter the template side, something that stays within the directive.
I know this is a lot to ask, sorry if I am not explaining my self properly, if so I will try to do better.
The following would be correct values:
Integers:1,2,3...
Floats:1.3, 0.3, 0,03...
Negative integers:-1,-2,-3...
Negative floats:-1.3, -0.3, -0.03...
Scientific notation:3e18, 3E18
Scientific notation:-6e18, -7E18
Scientific notation:-2.2e18, 2.2E-18
Scientific notation:-0.22e18, 2.2E-18
Scientific notation:0.22e-18
Any integer, float or scientific notation represented with e or E.
Related
I want to put unicode characters into the URL but some of them are "invisible" like U+0000. However, if I do String.fromCodePoint(0).length it is equal to 1. How do I check that it is an invisible character so I can instead display some other string like it's numeric representation (such as /unicode/u+0000) instead of /unicode/<blank>.
Currently I have this:
var slug = glyph.trim()
? glyph.match(/[\?\&\#\/]/)
? `u+${unicode}`
: glyph
: `u+${unicode}`
But it doesn't work for the zero-width (invisible) character U+0000 which has length 1.
https://en.wikipedia.org/wiki/Whitespace_character
How to detect invisible (zero-width or whitespace) characters
You need to figure out which characters render with column width < 1. I am not aware of a JS module that correctly implements the relevant part of Unicode, so let's use a programming language that is not a constant disappointment when it comes to processing text.
There is not a singular reason for column width < 1 that these characters have in common.
› perl -mUnicode::GCString -e'
for (0..0x1ffff) {
my $s = Unicode::GCString->new(chr $_);
print sprintf("U+%04X ", $_) if $s->columns < 1
}'
U+0000 U+0001 U+0002 U+0003 U+0004 U+0005 U+0006 U+0007 U+0008 U+0009 U+000A
U+000B U+000C U+000D U+000E U+000F U+0010 U+0011 U+0012 U+0013 U+0014 U+0015
U+0016 U+0017 U+0018 U+0019 U+001A U+001B U+001C U+001D U+001E U+001F U+007F
U+0080 U+0081 U+0082 U+0083 U+0084 U+0085 U+0086 U+0087 U+0088 U+0089 U+008A
U+008B U+008C U+008D U+008E U+008F U+0090 U+0091 U+0092 U+0093 U+0094 U+0095
U+0096 U+0097 U+0098 U+0099 U+009A U+009B U+009C U+009D U+009E U+009F U+00AD
U+0300 U+0301 U+0302 U+0303 U+0304 U+0305 U+0306 U+0307 U+0308 U+0309 U+030A
U+030B U+030C U+030D U+030E U+030F U+0310 U+0311 U+0312 U+0313 U+0314 U+0315
U+0316 U+0317 U+0318 U+0319 U+031A U+031B U+031C U+031D U+031E U+031F U+0320
U+0321 U+0322 U+0323 U+0324 U+0325 U+0326 U+0327 U+0328 U+0329 U+032A U+032B
U+032C U+032D U+032E U+032F U+0330 U+0331 U+0332 U+0333 U+0334 U+0335 U+0336
U+0337 U+0338 U+0339 U+033A U+033B U+033C U+033D U+033E U+033F U+0340 U+0341
U+0342 U+0343 U+0344 U+0345 U+0346 U+0347 U+0348 U+0349 U+034A U+034B U+034C
U+034D U+034E U+034F U+0350 U+0351 U+0352 U+0353 U+0354 U+0355 U+0356 U+0357
U+0358 U+0359 U+035A U+035B U+035C U+035D U+035E U+035F U+0360 U+0361 U+0362
U+0363 U+0364 U+0365 U+0366 U+0367 U+0368 U+0369 U+036A U+036B U+036C U+036D
U+036E U+036F U+0483 U+0484 U+0485 U+0486 U+0487 U+0488 U+0489 U+0591 U+0592
U+0593 U+0594 U+0595 U+0596 U+0597 U+0598 U+0599 U+059A U+059B U+059C U+059D
U+059E U+059F U+05A0 U+05A1 U+05A2 U+05A3 U+05A4 U+05A5 U+05A6 U+05A7 U+05A8
U+05A9 U+05AA U+05AB U+05AC U+05AD U+05AE U+05AF U+05B0 U+05B1 U+05B2 U+05B3
U+05B4 U+05B5 U+05B6 U+05B7 U+05B8 U+05B9 U+05BA U+05BB U+05BC U+05BD U+05BF
U+05C1 U+05C2 U+05C4 U+05C5 U+05C7 U+0600 U+0601 U+0602 U+0603 U+0604 U+0605
U+0610 U+0611 U+0612 U+0613 U+0614 U+0615 U+0616 U+0617 U+0618 U+0619 U+061A
U+061C U+064B U+064C U+064D U+064E U+064F U+0650 U+0651 U+0652 U+0653 U+0654
U+0655 U+0656 U+0657 U+0658 U+0659 U+065A U+065B U+065C U+065D U+065E U+065F
U+0670 U+06D6 U+06D7 U+06D8 U+06D9 U+06DA U+06DB U+06DC U+06DD U+06DF U+06E0
U+06E1 U+06E2 U+06E3 U+06E4 U+06E7 U+06E8 U+06EA U+06EB U+06EC U+06ED U+070F
U+0711 U+0730 U+0731 U+0732 U+0733 U+0734 U+0735 U+0736 U+0737 U+0738 U+0739
U+073A U+073B U+073C U+073D U+073E U+073F U+0740 U+0741 U+0742 U+0743 U+0744
U+0745 U+0746 U+0747 U+0748 U+0749 U+074A U+07A6 U+07A7 U+07A8 U+07A9 U+07AA
U+07AB U+07AC U+07AD U+07AE U+07AF U+07B0 U+07EB U+07EC U+07ED U+07EE U+07EF
U+07F0 U+07F1 U+07F2 U+07F3 U+0816 U+0817 U+0818 U+0819 U+081B U+081C U+081D
U+081E U+081F U+0820 U+0821 U+0822 U+0823 U+0825 U+0826 U+0827 U+0829 U+082A
U+082B U+082C U+082D U+0859 U+085A U+085B U+08E3 U+08E4 U+08E5 U+08E6 U+08E7
U+08E8 U+08E9 U+08EA U+08EB U+08EC U+08ED U+08EE U+08EF U+08F0 U+08F1 U+08F2
U+08F3 U+08F4 U+08F5 U+08F6 U+08F7 U+08F8 U+08F9 U+08FA U+08FB U+08FC U+08FD
U+08FE U+08FF U+0900 U+0901 U+0902 U+093A U+093C U+0941 U+0942 U+0943 U+0944
U+0945 U+0946 U+0947 U+0948 U+094D U+0951 U+0952 U+0953 U+0954 U+0955 U+0956
U+0957 U+0962 U+0963 U+0981 U+09BC U+09C1 U+09C2 U+09C3 U+09C4 U+09CD U+09E2
U+09E3 U+0A01 U+0A02 U+0A3C U+0A41 U+0A42 U+0A47 U+0A48 U+0A4B U+0A4C U+0A4D
U+0A51 U+0A70 U+0A71 U+0A75 U+0A81 U+0A82 U+0ABC U+0AC1 U+0AC2 U+0AC3 U+0AC4
U+0AC5 U+0AC7 U+0AC8 U+0ACD U+0AE2 U+0AE3 U+0B01 U+0B3C U+0B3F U+0B41 U+0B42
U+0B43 U+0B44 U+0B4D U+0B56 U+0B62 U+0B63 U+0B82 U+0BC0 U+0BCD U+0C00 U+0C3E
U+0C3F U+0C40 U+0C46 U+0C47 U+0C48 U+0C4A U+0C4B U+0C4C U+0C4D U+0C55 U+0C56
U+0C62 U+0C63 U+0C81 U+0CBC U+0CBF U+0CC6 U+0CCC U+0CCD U+0CE2 U+0CE3 U+0D01
U+0D41 U+0D42 U+0D43 U+0D44 U+0D4D U+0D62 U+0D63 U+0DCA U+0DD2 U+0DD3 U+0DD4
U+0DD6 U+0E31 U+0E34 U+0E35 U+0E36 U+0E37 U+0E38 U+0E39 U+0E3A U+0E47 U+0E48
U+0E49 U+0E4A U+0E4B U+0E4C U+0E4D U+0E4E U+0EB1 U+0EB4 U+0EB5 U+0EB6 U+0EB7
U+0EB8 U+0EB9 U+0EBB U+0EBC U+0EC8 U+0EC9 U+0ECA U+0ECB U+0ECC U+0ECD U+0F18
U+0F19 U+0F35 U+0F37 U+0F39 U+0F71 U+0F72 U+0F73 U+0F74 U+0F75 U+0F76 U+0F77
U+0F78 U+0F79 U+0F7A U+0F7B U+0F7C U+0F7D U+0F7E U+0F80 U+0F81 U+0F82 U+0F83
U+0F84 U+0F86 U+0F87 U+0F8D U+0F8E U+0F8F U+0F90 U+0F91 U+0F92 U+0F93 U+0F94
U+0F95 U+0F96 U+0F97 U+0F99 U+0F9A U+0F9B U+0F9C U+0F9D U+0F9E U+0F9F U+0FA0
U+0FA1 U+0FA2 U+0FA3 U+0FA4 U+0FA5 U+0FA6 U+0FA7 U+0FA8 U+0FA9 U+0FAA U+0FAB
U+0FAC U+0FAD U+0FAE U+0FAF U+0FB0 U+0FB1 U+0FB2 U+0FB3 U+0FB4 U+0FB5 U+0FB6
U+0FB7 U+0FB8 U+0FB9 U+0FBA U+0FBB U+0FBC U+0FC6 U+102D U+102E U+102F U+1030
U+1032 U+1033 U+1034 U+1035 U+1036 U+1037 U+1039 U+103A U+103D U+103E U+1058
U+1059 U+105E U+105F U+1060 U+1071 U+1072 U+1073 U+1074 U+1082 U+1085 U+1086
U+108D U+109D U+135D U+135E U+135F U+1712 U+1713 U+1714 U+1732 U+1733 U+1734
U+1752 U+1753 U+1772 U+1773 U+17B4 U+17B5 U+17B7 U+17B8 U+17B9 U+17BA U+17BB
U+17BC U+17BD U+17C6 U+17C9 U+17CA U+17CB U+17CC U+17CD U+17CE U+17CF U+17D0
U+17D1 U+17D2 U+17D3 U+17DD U+180B U+180C U+180D U+180E U+18A9 U+1920 U+1921
U+1922 U+1927 U+1928 U+1932 U+1939 U+193A U+193B U+1A17 U+1A18 U+1A1B U+1A56
U+1A58 U+1A59 U+1A5A U+1A5B U+1A5C U+1A5D U+1A5E U+1A60 U+1A62 U+1A65 U+1A66
U+1A67 U+1A68 U+1A69 U+1A6A U+1A6B U+1A6C U+1A73 U+1A74 U+1A75 U+1A76 U+1A77
U+1A78 U+1A79 U+1A7A U+1A7B U+1A7C U+1A7F U+1AB0 U+1AB1 U+1AB2 U+1AB3 U+1AB4
U+1AB5 U+1AB6 U+1AB7 U+1AB8 U+1AB9 U+1ABA U+1ABB U+1ABC U+1ABD U+1ABE U+1B00
U+1B01 U+1B02 U+1B03 U+1B34 U+1B36 U+1B37 U+1B38 U+1B39 U+1B3A U+1B3C U+1B42
U+1B6B U+1B6C U+1B6D U+1B6E U+1B6F U+1B70 U+1B71 U+1B72 U+1B73 U+1B80 U+1B81
U+1BA2 U+1BA3 U+1BA4 U+1BA5 U+1BA8 U+1BA9 U+1BAB U+1BAC U+1BAD U+1BE6 U+1BE8
U+1BE9 U+1BED U+1BEF U+1BF0 U+1BF1 U+1C2C U+1C2D U+1C2E U+1C2F U+1C30 U+1C31
U+1C32 U+1C33 U+1C36 U+1C37 U+1CD0 U+1CD1 U+1CD2 U+1CD4 U+1CD5 U+1CD6 U+1CD7
U+1CD8 U+1CD9 U+1CDA U+1CDB U+1CDC U+1CDD U+1CDE U+1CDF U+1CE0 U+1CE2 U+1CE3
U+1CE4 U+1CE5 U+1CE6 U+1CE7 U+1CE8 U+1CED U+1CF4 U+1CF8 U+1CF9 U+1DC0 U+1DC1
U+1DC2 U+1DC3 U+1DC4 U+1DC5 U+1DC6 U+1DC7 U+1DC8 U+1DC9 U+1DCA U+1DCB U+1DCC
U+1DCD U+1DCE U+1DCF U+1DD0 U+1DD1 U+1DD2 U+1DD3 U+1DD4 U+1DD5 U+1DD6 U+1DD7
U+1DD8 U+1DD9 U+1DDA U+1DDB U+1DDC U+1DDD U+1DDE U+1DDF U+1DE0 U+1DE1 U+1DE2
U+1DE3 U+1DE4 U+1DE5 U+1DE6 U+1DE7 U+1DE8 U+1DE9 U+1DEA U+1DEB U+1DEC U+1DED
U+1DEE U+1DEF U+1DF0 U+1DF1 U+1DF2 U+1DF3 U+1DF4 U+1DF5 U+1DFC U+1DFD U+1DFE
U+1DFF U+200B U+200C U+200D U+200E U+200F U+2028 U+2029 U+202A U+202B U+202C
U+202D U+202E U+2060 U+2061 U+2062 U+2063 U+2064 U+2066 U+2067 U+2068 U+2069
U+206A U+206B U+206C U+206D U+206E U+206F U+20D0 U+20D1 U+20D2 U+20D3 U+20D4
U+20D5 U+20D6 U+20D7 U+20D8 U+20D9 U+20DA U+20DB U+20DC U+20DD U+20DE U+20DF
U+20E0 U+20E1 U+20E2 U+20E3 U+20E4 U+20E5 U+20E6 U+20E7 U+20E8 U+20E9 U+20EA
U+20EB U+20EC U+20ED U+20EE U+20EF U+20F0 U+2CEF U+2CF0 U+2CF1 U+2D7F U+2DE0
U+2DE1 U+2DE2 U+2DE3 U+2DE4 U+2DE5 U+2DE6 U+2DE7 U+2DE8 U+2DE9 U+2DEA U+2DEB
U+2DEC U+2DED U+2DEE U+2DEF U+2DF0 U+2DF1 U+2DF2 U+2DF3 U+2DF4 U+2DF5 U+2DF6
U+2DF7 U+2DF8 U+2DF9 U+2DFA U+2DFB U+2DFC U+2DFD U+2DFE U+2DFF U+302A U+302B
U+302C U+302D U+3099 U+309A U+A66F U+A670 U+A671 U+A672 U+A674 U+A675 U+A676
U+A677 U+A678 U+A679 U+A67A U+A67B U+A67C U+A67D U+A69E U+A69F U+A6F0 U+A6F1
U+A802 U+A806 U+A80B U+A825 U+A826 U+A8C4 U+A8E0 U+A8E1 U+A8E2 U+A8E3 U+A8E4
U+A8E5 U+A8E6 U+A8E7 U+A8E8 U+A8E9 U+A8EA U+A8EB U+A8EC U+A8ED U+A8EE U+A8EF
U+A8F0 U+A8F1 U+A926 U+A927 U+A928 U+A929 U+A92A U+A92B U+A92C U+A92D U+A947
U+A948 U+A949 U+A94A U+A94B U+A94C U+A94D U+A94E U+A94F U+A950 U+A951 U+A980
U+A981 U+A982 U+A9B3 U+A9B6 U+A9B7 U+A9B8 U+A9B9 U+A9BC U+A9E5 U+AA29 U+AA2A
U+AA2B U+AA2C U+AA2D U+AA2E U+AA31 U+AA32 U+AA35 U+AA36 U+AA43 U+AA4C U+AA7C
U+AAB0 U+AAB2 U+AAB3 U+AAB4 U+AAB7 U+AAB8 U+AABE U+AABF U+AAC1 U+AAEC U+AAED
U+AAF6 U+ABE5 U+ABE8 U+ABED U+FB1E U+FE00 U+FE01 U+FE02 U+FE03 U+FE04 U+FE05
U+FE06 U+FE07 U+FE08 U+FE09 U+FE0A U+FE0B U+FE0C U+FE0D U+FE0E U+FE0F U+FE20
U+FE21 U+FE22 U+FE23 U+FE24 U+FE25 U+FE26 U+FE27 U+FE28 U+FE29 U+FE2A U+FE2B
U+FE2C U+FE2D U+FE2E U+FE2F U+FEFF U+FFF9 U+FFFA U+FFFB U+101FD U+102E0 U+10376
U+10377 U+10378 U+10379 U+1037A U+10A01 U+10A02 U+10A03 U+10A05 U+10A06 U+10A0C
U+10A0D U+10A0E U+10A0F U+10A38 U+10A39 U+10A3A U+10A3F U+10AE5 U+10AE6 U+11001
U+11038 U+11039 U+1103A U+1103B U+1103C U+1103D U+1103E U+1103F U+11040 U+11041
U+11042 U+11043 U+11044 U+11045 U+11046 U+1107F U+11080 U+11081 U+110B3 U+110B4
U+110B5 U+110B6 U+110B9 U+110BA U+110BD U+11100 U+11101 U+11102 U+11127 U+11128
U+11129 U+1112A U+1112B U+1112D U+1112E U+1112F U+11130 U+11131 U+11132 U+11133
U+11134 U+11173 U+11180 U+11181 U+111B6 U+111B7 U+111B8 U+111B9 U+111BA U+111BB
U+111BC U+111BD U+111BE U+111CA U+111CB U+111CC U+1122F U+11230 U+11231 U+11234
U+11236 U+11237 U+112DF U+112E3 U+112E4 U+112E5 U+112E6 U+112E7 U+112E8 U+112E9
U+112EA U+11300 U+11301 U+1133C U+11340 U+11366 U+11367 U+11368 U+11369 U+1136A
U+1136B U+1136C U+11370 U+11371 U+11372 U+11373 U+11374 U+114B3 U+114B4 U+114B5
U+114B6 U+114B7 U+114B8 U+114BA U+114BF U+114C0 U+114C2 U+114C3 U+115B2 U+115B3
U+115B4 U+115B5 U+115BC U+115BD U+115BF U+115C0 U+115DC U+115DD U+11633 U+11634
U+11635 U+11636 U+11637 U+11638 U+11639 U+1163A U+1163D U+1163F U+11640 U+116AB
U+116AD U+116B0 U+116B1 U+116B2 U+116B3 U+116B4 U+116B5 U+116B7 U+1171D U+1171E
U+1171F U+11722 U+11723 U+11724 U+11725 U+11727 U+11728 U+11729 U+1172A U+1172B
U+16AF0 U+16AF1 U+16AF2 U+16AF3 U+16AF4 U+16B30 U+16B31 U+16B32 U+16B33 U+16B34
U+16B35 U+16B36 U+16F8F U+16F90 U+16F91 U+16F92 U+1BC9D U+1BC9E U+1BCA0 U+1BCA1
U+1BCA2 U+1BCA3 U+1D167 U+1D168 U+1D169 U+1D173 U+1D174 U+1D175 U+1D176 U+1D177
U+1D178 U+1D179 U+1D17A U+1D17B U+1D17C U+1D17D U+1D17E U+1D17F U+1D180 U+1D181
U+1D182 U+1D185 U+1D186 U+1D187 U+1D188 U+1D189 U+1D18A U+1D18B U+1D1AA U+1D1AB
U+1D1AC U+1D1AD U+1D242 U+1D243 U+1D244 U+1DA00 U+1DA01 U+1DA02 U+1DA03 U+1DA04
U+1DA05 U+1DA06 U+1DA07 U+1DA08 U+1DA09 U+1DA0A U+1DA0B U+1DA0C U+1DA0D U+1DA0E
U+1DA0F U+1DA10 U+1DA11 U+1DA12 U+1DA13 U+1DA14 U+1DA15 U+1DA16 U+1DA17 U+1DA18
U+1DA19 U+1DA1A U+1DA1B U+1DA1C U+1DA1D U+1DA1E U+1DA1F U+1DA20 U+1DA21 U+1DA22
U+1DA23 U+1DA24 U+1DA25 U+1DA26 U+1DA27 U+1DA28 U+1DA29 U+1DA2A U+1DA2B U+1DA2C
U+1DA2D U+1DA2E U+1DA2F U+1DA30 U+1DA31 U+1DA32 U+1DA33 U+1DA34 U+1DA35 U+1DA36
U+1DA3B U+1DA3C U+1DA3D U+1DA3E U+1DA3F U+1DA40 U+1DA41 U+1DA42 U+1DA43 U+1DA44
U+1DA45 U+1DA46 U+1DA47 U+1DA48 U+1DA49 U+1DA4A U+1DA4B U+1DA4C U+1DA4D U+1DA4E
U+1DA4F U+1DA50 U+1DA51 U+1DA52 U+1DA53 U+1DA54 U+1DA55 U+1DA56 U+1DA57 U+1DA58
U+1DA59 U+1DA5A U+1DA5B U+1DA5C U+1DA5D U+1DA5E U+1DA5F U+1DA60 U+1DA61 U+1DA62
U+1DA63 U+1DA64 U+1DA65 U+1DA66 U+1DA67 U+1DA68 U+1DA69 U+1DA6A U+1DA6B U+1DA6C
U+1DA75 U+1DA84 U+1DA9B U+1DA9C U+1DA9D U+1DA9E U+1DA9F U+1DAA1 U+1DAA2 U+1DAA3
U+1DAA4 U+1DAA5 U+1DAA6 U+1DAA7 U+1DAA8 U+1DAA9 U+1DAAA U+1DAAB U+1DAAC U+1DAAD
U+1DAAE U+1DAAF U+1E8D0 U+1E8D1 U+1E8D2 U+1E8D3 U+1E8D4 U+1E8D5 U+1E8D6 U+E0001
U+E0020 U+E0021 U+E0022 U+E0023 U+E0024 U+E0025 U+E0026 U+E0027 U+E0028 U+E0029
U+E002A U+E002B U+E002C U+E002D U+E002E U+E002F U+E0030 U+E0031 U+E0032 U+E0033
U+E0034 U+E0035 U+E0036 U+E0037 U+E0038 U+E0039 U+E003A U+E003B U+E003C U+E003D
U+E003E U+E003F U+E0040 U+E0041 U+E0042 U+E0043 U+E0044 U+E0045 U+E0046 U+E0047
U+E0048 U+E0049 U+E004A U+E004B U+E004C U+E004D U+E004E U+E004F U+E0050 U+E0051
U+E0052 U+E0053 U+E0054 U+E0055 U+E0056 U+E0057 U+E0058 U+E0059 U+E005A U+E005B
U+E005C U+E005D U+E005E U+E005F U+E0060 U+E0061 U+E0062 U+E0063 U+E0064 U+E0065
U+E0066 U+E0067 U+E0068 U+E0069 U+E006A U+E006B U+E006C U+E006D U+E006E U+E006F
U+E0070 U+E0071 U+E0072 U+E0073 U+E0074 U+E0075 U+E0076 U+E0077 U+E0078 U+E0079
U+E007A U+E007B U+E007C U+E007D U+E007E U+E007F U+E0100 U+E0101 U+E0102 U+E0103
U+E0104 U+E0105 U+E0106 U+E0107 U+E0108 U+E0109 U+E010A U+E010B U+E010C U+E010D
U+E010E U+E010F U+E0110 U+E0111 U+E0112 U+E0113 U+E0114 U+E0115 U+E0116 U+E0117
U+E0118 U+E0119 U+E011A U+E011B U+E011C U+E011D U+E011E U+E011F U+E0120 U+E0121
U+E0122 U+E0123 U+E0124 U+E0125 U+E0126 U+E0127 U+E0128 U+E0129 U+E012A U+E012B
U+E012C U+E012D U+E012E U+E012F U+E0130 U+E0131 U+E0132 U+E0133 U+E0134 U+E0135
U+E0136 U+E0137 U+E0138 U+E0139 U+E013A U+E013B U+E013C U+E013D U+E013E U+E013F
U+E0140 U+E0141 U+E0142 U+E0143 U+E0144 U+E0145 U+E0146 U+E0147 U+E0148 U+E0149
U+E014A U+E014B U+E014C U+E014D U+E014E U+E014F U+E0150 U+E0151 U+E0152 U+E0153
U+E0154 U+E0155 U+E0156 U+E0157 U+E0158 U+E0159 U+E015A U+E015B U+E015C U+E015D
U+E015E U+E015F U+E0160 U+E0161 U+E0162 U+E0163 U+E0164 U+E0165 U+E0166 U+E0167
U+E0168 U+E0169 U+E016A U+E016B U+E016C U+E016D U+E016E U+E016F U+E0170 U+E0171
U+E0172 U+E0173 U+E0174 U+E0175 U+E0176 U+E0177 U+E0178 U+E0179 U+E017A U+E017B
U+E017C U+E017D U+E017E U+E017F U+E0180 U+E0181 U+E0182 U+E0183 U+E0184 U+E0185
U+E0186 U+E0187 U+E0188 U+E0189 U+E018A U+E018B U+E018C U+E018D U+E018E U+E018F
U+E0190 U+E0191 U+E0192 U+E0193 U+E0194 U+E0195 U+E0196 U+E0197 U+E0198 U+E0199
U+E019A U+E019B U+E019C U+E019D U+E019E U+E019F U+E01A0 U+E01A1 U+E01A2 U+E01A3
U+E01A4 U+E01A5 U+E01A6 U+E01A7 U+E01A8 U+E01A9 U+E01AA U+E01AB U+E01AC U+E01AD
U+E01AE U+E01AF U+E01B0 U+E01B1 U+E01B2 U+E01B3 U+E01B4 U+E01B5 U+E01B6 U+E01B7
U+E01B8 U+E01B9 U+E01BA U+E01BB U+E01BC U+E01BD U+E01BE U+E01BF U+E01C0 U+E01C1
U+E01C2 U+E01C3 U+E01C4 U+E01C5 U+E01C6 U+E01C7 U+E01C8 U+E01C9 U+E01CA U+E01CB
U+E01CC U+E01CD U+E01CE U+E01CF U+E01D0 U+E01D1 U+E01D2 U+E01D3 U+E01D4 U+E01D5
U+E01D6 U+E01D7 U+E01D8 U+E01D9 U+E01DA U+E01DB U+E01DC U+E01DD U+E01DE U+E01DF
U+E01E0 U+E01E1 U+E01E2 U+E01E3 U+E01E4 U+E01E5 U+E01E6 U+E01E7 U+E01E8 U+E01E9
U+E01EA U+E01EB U+E01EC U+E01ED U+E01EE U+E01EF
Update
"Note that there are many more symbols that may not be visible."
null (\u{0}) has been added. If you want to detect all whitespaces regardless of width use the meta sequence plus, quantifier \s+ (+ quantifier matches one or more of the characters that precedes it.) and an alternate(s) | between it and the rest of the regex (| is an OR gate).
This may be a XY problem. If you really need to replace zero width characters with [Fill in the blank] then proceed. If you need a way to copy them and keep the url intact then encode the url with encodeURIComponent() instead.
There's only four zero width characters:
U+feff - zero width no-break space
U+200b - zero width space
U+200c - zero width non-joiner
U+200d - zero width joiner
In order to use Unicode in RegEx we must use the unicode flag and the following syntax:
U+feff >>> \u{feff}
The following demo will extract the slug from a url and removes the previously mentioned zero width characters. If you wish to replace them with something (I have no idea why it would be useful to do so...), then do the following:
First Parameter: url |String| (required)
Second Parameter: slug |Boolean| (default: true) Returns the slug by default. If false it returns the full url. Pass explicitly in order to pass third parameter explicitly.
Third Parameter: rpl String or Regex This is the replacement characters. By default it will remove zero width characters without a replacement.
// Each url has a zero width character in the slug
let u200b = `https://example.com/path/to/slugs`;
let ufeff = `https://example.com/path/to/slugs`;
let u200c = `https://example.com/path/to/slugs`;
let u200d = `https://example.com/path/to/slugs`;
const getSlug = (url, slug = true, rpl = '') => {
let regex = /\u{0}+|\u{feff}+|\u{200b}+|\u{200c}+|\u{200d}/gu;
let string;
if (slug) {
string = url.split('/').pop().trim();
console.log(`Old Length of slug: ${string.length}`);
} else {
string = url;
console.log(`Old Length of url: ${string.length}`);
}
let clean = string.replace(regex, rpl);
console.log(`New Length: ${clean.length}`);
return clean;
}
getSlug(u200b);
getSlug(ufeff);
getSlug(u200c);
getSlug(u200d);
Something like this would do the replace:
String.prototype.replaceAll = function (stringToFind, stringToReplace) {
if (stringToFind === stringToReplace) return this;
var temp = this;
var index = temp.indexOf(stringToFind);
while (index != -1) {
temp = temp.replace(stringToFind, stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
};
var s = "A\0Z";
console.log(s.length); // returns 3
console.log(s.charCodeAt(1)); // returns 0
console.log(s.replaceAll("\0", "{NULLCHAR}"));
I have a function that create LI and href element.
function getsubject(s) {
if (s <= 10) {
var sub = ['Choose subject','math', 'physics', 'chemistry', 'biology'];
} else {
var sub = [ 'Choose subject','math', 'physics', 'chemistry', 'biology', 'accounts', 'BMT'];
}
var subList = sub.length;
// var subl = document.getElementById("listul");
// var a = document.querySelectorAll('#listul .sli').length;
var elements = document.getElementsByClassName("sli");
while(elements.length > 0){
elements[0].parentNode.removeChild(elements[0]);
}
var liElem="";
for(var a =0;a<subList;a++){
liElem += '<li class="sli">'+sub[a]+'</li>';
}
document.getElementById('listul').innerHTML=liElem;
}
and HTML
<div class="list select_style">
<ol id="listul">
<li>choose subject</li>
</ol>
</div>
when I passing using created function without parameter that work.
when I passing parameters from function can't work.
Quotes
You must pass variables with quotes into onclick.
For now getsubject(s) appends string:
<li class="sli">chemistry</li>
You can note that onclick handler is invalid as it invokes ub function on undefined value chemistry.
But you can call functions on strings like this ub("chemistry").
So the solution is to place quotes around the values in the function call:
for(var a =0;a<subList;a++){
liElem += '<li class="sli">'+sub[a]+'</li>';
}
Template literal
Better approach (but not available on all browsers is to use ECMAScript template literals:
for(var a =0;a<subList;a++){
liElem += `
<li class="sli">
<a href="#" onclick="ub('${sub[a]}');">
${sub[a]}
</a>
</li>
`;
}
Template literal can be used as normal string with "" or '' quotes, but it can be multiline and could contain notation ${variable} which means to place value of variable in that place in the string.
JQuery approach
It's worth to consider something better than plain text html rendering.
The equivalent code using jQuery looks like this:
var liNode = $('<li class="sli"></li>');
$('').click(function() {
// Call ud from the handler when link is clicked
ud(value);
}).appendTo(liNode);
liNode.appendTo($('.sli'));
http://jsfiddle.net/f4Zkm/213/
HTML
<div ng-app>
<div ng-controller="MyController">
<input type="search" ng-model="search" placeholder="Search...">
<ul>
<li ng-repeat="name in names | filter:filterBySearch">
{{ name }}
</li>
</ul>
</div>
</div>
app.js
function escapeRegExp(string){
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function MyController($scope) {
$scope.names = [
'Lolita Dipietro',
'Annice Guernsey',
'Gerri Rall',
'Ginette Pinales',
'Lon Rondon',
'Jennine Marcos',
'Roxann Hooser',
'Brendon Loth',
'Ilda Bogdan',
'Jani Fan',
'Grace Soller',
'Everette Costantino',
'Andy Hume',
'Omar Davie',
'Jerrica Hillery',
'Charline Cogar',
'Melda Diorio',
'Rita Abbott',
'Setsuko Minger',
'Aretha Paige'];
$scope.search = '';
var regex;
$scope.$watch('search', function (value) {
regex = new RegExp('\\b' + escapeRegExp(value), 'i');
});
$scope.filterBySearch = function(name) {
if (!$scope.search) return true;
return regex.test(name);
};
}
From the above example, I have been trying to create a wildcard regex search by using a special character '*' but I haven't been able to loop through the array.
Current output: If the input is di, it showing all the related matches.
Required: What I am trying to get is, if the input is di*/*(any input), it should show all the matches as per the given input.
There are a couple issues with your approach. First, you are escaping * in your escape routine, so it can not be used by the client.
Second, you are not anchoring your lines, so the match can occur anywhere.
To fix, remove the asterisk from the escape function :
function escapeRegExp(string){
return string.replace(/([.+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
Then in your watch function replace * with .* and add line anchors :
$scope.$watch('search', function (value) {
var escaped = escapeRegExp(value);
var formatted = escaped.replace('*', '.*')
if(formatted.indexOf('*') === -1){
formatted = '.*' + formatted + '.*'
}
regex = new RegExp('^' + formatted + '$', 'im');
});
Here is a fiddle
I have this number.
20.79
I need see the number as
20,79
Or
1.200,76 €
How can I change the . by , and add € currency?
Thanks!
Solution
app.filter('customCurrency', function(){
return function(input, symbol, place){
if(isNaN(input)){
return input;
} else {
var symbol = symbol || '$';
var place = place === undefined ? true : place;
if(place === true){
return symbol + input;
} else{
var new_input = input.replace(".", ",");
return new_input + symbol;
}
}
}
})
You can do it by simply changing your Locale to match the European currency:
Import this library
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.0/angular-locale_de-de.js"></script>
In your html
<div>{{ myNumber | currency: '€' }}</div>
In your controller
$scope.myNumber = 1220.79;
Result: 1.220,79 €
Please check it: JSFiddle Demo
Use the currency filter:
In your Angular controller:
$scope.myNumber = 20.79;
In your HTML page:
<div>{{myNumber | currency}}</div>
Update: If you need to display in €, 2 options:
Set your locale to your country: <script src="i18n/angular-locale_de-de.js"></script> (best option).
Display it without currency filter: {{(myNumber | number: 2) + " €"}}.
Demo on JSFiddle.
I want to put 2 customs filters on a data. Each filter is working perfectly independently, but when I put the 2 on the same data, I have an error message (TypeError: input.replace is not a function), but if I comment this, I have another error message (Error: [$sce:itype] Attempted to trust a non-string value in a content requiring a string: Context: html)
The 2 customs filters are goBold which take no argument, and limitHellip which takes the maximum length of the string as an argument.
thanks a lot, here is the code :
angular.module('appFilters', []).
filter('goBold', function($sce) {
return function (input) {
input = input.replace(' filter ',' <strong>WORD FILTERED</strong> ');
return $sce.trustAsHtml( input );
}
}).
filter('limitHellip', function($sce) {
return function (input, limit) {
console.log(limit);
if( input.length > 100 ) {
input = input.substring(0,100);
var index = input.lastIndexOf(" ");
input = input.substring(0,index) + "…";
}
return $sce.trustAsHtml( input );
}
});
<ion-content class="has-subheader">
<ion-item class="element item item-divider" data-ng-repeat="item in blocInfos" >
<a href="#/list/{{ item.url }}">
<img data-ng-src="img/{{ item.imageUrl }}" alt="">
<h2 class="title">{{ item.title }}</h2>
</a>
<p data-ng-bind-html="item.text | limitHellip: 100 | goBold" class="wrap"></p>
</ion-item>
</ion-content>
This is because your first filter return an $sce.trusAsHtml() which is an Object and not a string so you can't call the replace() method.
So, you have to change it into a String
Plunkr
Filters
angular.module('appFilters', []).
filter('goBold', function($sce) {
return function (input) {
input = input.toString(); //This line was added
input = input.replace(' filter ',' <strong>WORD FILTERED</strong> ');
return $sce.trustAsHtml( input );
}
}).
filter('limitHellip', function($sce) {
return function (input, limit) {
input = input.toString(); //Maybe you have to add it here too
console.log(limit);
if( input.length > limit ) {
input = input.substring(0,limit);
var index = input.lastIndexOf(" ");
input = input.substring(0,index) + "…";
}
return $sce.trustAsHtml( input );
}
})