<SCRIPT>
FunctionDelhtmltag (STR)
{
VaRSTR = Str. Replace (/<\/? [^>] *>/Gim ,"");//Remove all HTML tags
VaRResult = Str. Replace (/(^ \ s +) | (\ s + $)/g ,"");//Remove leading and trailing Spaces
ReturnResult. Replace (/\ s/g ,"");//RemoveArticleIntermediate Space
}
</SCRIPT>
The above method is to remove spaces ~~ So we often encounter similar requirements, and you never know what the user will lose, so you only have to try to avoid entering what you don't want. The above changes can also become verified to exist.
Space prompt
//Verify whether the content contains spaces
FunctionChecktextspace (OBJ, temp ){
VaRReg =/(^ \ s +) | (\ s + $)/g;
VaRAlertvalue = "the input content contains spaces. Please input a new one! ";
//Temp is used to identify whether the content can contain spaces. 1 indicates that the content can exist. 0 indicates that the content does not exist.
If(Temp = 1 ){
Reg =/(^ \ s {5,}) | (\ s {5,} $) | (\ s {5,})/g;
Alertvalue = "the number of consecutive spaces entered in the content exceeds 5. Please try again! ";
}
If(Reg. Test (obj. Value )){
Alert (alertvalue );
OBJ. Focus ();
Return False;
}
}
The above sectionCodeI have met a requirement, and you can change it by yourself. I will explain it briefly (Do not spray it ):
^ Match the start of a string
$ End of matching string
/S match any blank characters
/(^ \ S +) | (\ s + $)/g this regular expression indicates whether the Matching content contains spaces. It can be matched either in the front and back of the regular expression or in the middle of the regular expression.
/(^ \ S {5,}) | (\ s {5, }$) | (\ s {5 ,}) the/g regular expression is modified by another verification method. It mainly matches the number of consecutive input spaces.
\ S {5,} indicates matching five or more times
\ S * Indicates zero or more times.
\ S + This indicates repeated once or more times
\ S? This indicates zero or one repetition.
These are related to space verification. I want to help you!
In addition, some other regular expressions are provided.
For exampleMatch any character except linefeed
For example, \ W standsMatch letters, numbers, underscores, or Chinese Characters
Hope to help you ~~~