JavaScript implementation code for filtering spaces with regular expressions
<html><head><script type="text/javascript"> // Delete the spaces on the left and right ends function trim(str){ $a=str.replace(/(^/s*)|(/s*$)/g, ""); alert($a.length); // alert(str.length); } // Delete the spaces on the left function ltrim(str){ return str.replace(/(^/s*)/g,""); } // Delete the spaces on the right function rtrim(str){ return str.replace(/(/s*$)/g,""); } </script> </head><body><form> Delete the spaces on the left and right ends: <input type="text" value="" onblur= "trim(this.value)"><br/> Delete the spaces on the left: <input type="text" value="" onblur= "ltrim(this.value)"><br/> Delete the spaces on the right<input type="text" value="" onblur= "rtrim(this.value)"></form></body></form>The above implementation code for filtering spaces using regular expressions is the entire content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.