Trying to write logic if string has special character /
or %
replace that from the string so first i have check if special character is part of the string then replace it else return the text that was passed. E.g Tylenol 2/ml
or Tylenol .05%
output should be Tylenol 2ml
and Tylenol .05
. hasChar
always return false what is correct approach or regex to use ?
main.js
function removeSpecialyCharacter(txt){
let str = txt;
if(hasChar(txt)){
str = txt.replace(/[^a-zA-Z ]/g, "");
}
return str;
}
function hasChar(str){
return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
}