I am trying to use this function to create 2 results from value
function split(val){
return val.split( /,\s*/ );
};
value = "Jim, ";
var terms = split( value );
terms;
All other browsers including IE9, will produce terms = ["Jim", ""]
However, IE8 and probably IE7 produces this : terms = ["Jim"]
Does anyone have any suggestions or alternatives that could possibly work for IE8 ?
You might be better off going with:
val.split(',')
This seems to work consistently in all browsers.
Any trailing whitespace after the commas still has to be stripped off afterwards. Something along the lines of:
for (var i = 0; i < terms.length; i++) {
terms[i] = terms[i].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
Apparently, in IE8 and earlier, empty-string matches are ignored by split()
when a regex parameter is used. A string parameter works fine:
'axx'.split('x') // All browsers: ["a", "", ""]
'axx'.split(/x/) // IE6/7/8: ["a"], all other browsers: ["a", "", ""]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With