<script>
function Delhtmltag (str)
{
var str=str.replace (/<\/?[ ^>]*>/gim, "");//Remove all HTML tags
var result=str.replace (/(^\s+) | ( \s+$)/g, "");//Remove space before and after
Return result.replace (/\s/g, "");//Remove the middle space of the article
}
</script>
The above method is the way to remove the space ~ ~ so we often encounter similar requirements, you never know what users will lose, then you can only try to avoid the input you do not want. The above changes can also become a verification of the existence
Spaces give a hint
Verify that the content contains spaces
function Checktextspace (obj,temp) {
var reg=/(^\s+) | (\s+$)/g;
var alertvalue= "input contains spaces, please enter new!";
Temp is used to identify whether the content is allowed to exist in spaces 1 for the existence of 0 for non-existent
if (temp==1) {
reg=/(^\s{5,}) | (\s{5,}$) | (\s{5,})/g;
Alertvalue= "content of more than 5 consecutive input spaces, please re-enter! ";
}
if (Reg.test (Obj.value)) {
alert (Alertvalue);
Obj.focus ();
return false;
}
}
The above code is I met a need to change, you can also make your own changes, I would simply explain (master do not spray):
^ Start of matching string
$ match End of string
/s matches any white space character
/(^\s+) | (\s+$)/g This is the match content contains a space, regardless of the front or center, can match to
/(^\s{5,}) | (\s{5,}$) | (\s{5,})/g This regular is I do another validation change, mainly to match the number of consecutive input spaces
\s{5,} This representative matches 5 or more times
\s* the representative repeats 0 or more times.
\s+ the representative repeats 1 or more times.
\s, the representative repeats 0 or 1 times.
Regular Go Space method