Reputation: 1632
I have created a jquery function to format my text box data....such that I have a formatted output to my input box.
jQuery.fn.singleDotHyphen = function(){
return this.each(function(){
var $this = $(this);
$this.val(function(){
return $this.val()
.replace(/\.{2,}/g, '.')
.replace(/\'{2,}/g, "\'")
.replace(/\,{2,}/g, ",")
.replace(/\n{3,}/g, "\n\n")
.replace(/\s{2,}/g, " ")
.replace(/-{2,}/g, '-');
});
});
};
I have created it for newline that if more than 3 new lines are present than it convert it to 2 newline. But issue is if it find more than 3 nwe line than it convert it two space. How can I differentiate in both constraints that is of space and newline.
Upvotes: 0
Views: 226
Reputation: 19305
\s
matches any white-space character, including space, tab and linefeed.
Switch from /\s{2,}/g
to / {2,}/g
if you want to match literal spaces only.
Upvotes: 1