I'm using the below code to try to trim the string in Javascript but am getting the error mentioned in the title:
function trim(str) {
return str.replace(/^\s+|\s+$/g,'');
}
Edit:
I fixed the problem.... sorry I should have put the code on how I was calling it too.... realized I accidentally was passing the object of the form field itself rather than its value.
str
is probably not a stringregex
string itself, which mightn't be good anyway.str.toString().replace(/^\s+|\s+$/g,'')
instead.