Reputation: 1
I am JSF with PrimeFaces 5.1 in my project need onBlur remove specify character i.e in text 01,02,03,,
or 01,02,03
or 01,02,03,,,,
this text box value I need 01,02,03
using javascript is possible or anyother way
Upvotes: 0
Views: 116
Reputation: 4225
var input = "01,02,03,,,,";
//Keep checking if the trailing character is ','
while(input && input.charAt(input.length-1) == ","){
//if true trim the last character and continue
input = input.substring(0,input.length-1);
}
console.log(input);
Upvotes: 0
Reputation: 2819
use this trimRight method: https://www.sitepoint.com/trimming-strings-in-javascript/
String.prototype.trimRight = function(charlist) {
if (charlist === undefined)
charlist = "\s";
return this.replace(new RegExp("[" + charlist + "]+$"), "");
};
console.log("01,02,03,,,".trimRight(','));
Upvotes: 1