vignesh kumar
vignesh kumar

Reputation: 1

Modify inputText value onBlur

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

Answers (2)

Sunil B N
Sunil B N

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

WalksAway
WalksAway

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

Related Questions