Removing Double space from a textbox using REGEX
Input:
"I want to remove double space from textbox."
Output:
"I want to remove double space from textbox."
function valid(f) {
return f.replace(/^\s+开发者_开发知识库|\s+$/g,'').replace(/\s+/g,' ');
}
I have called this event onblur="valid(this);"
You need to be accessing the value of the input... in your above code you're trying to run a regex on an input object.
function valid(f) {
f.value=f.value.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' ');
return true;
}
Try:
return f.replace(/ +/,' ');
You have to get the value of the textbox, and put the result back in the value:
onblur="this.value = valid(this.value);"
精彩评论