Deleting spaces using the regular expression s + in js almost solves this problem. I would like to share with you the examples used in this project. I hope this will be helpful to you.
The following two requirements are required in the reply box
A set of methods for removing spaces in JavaScript. The script home has previously released a lot of code for removing spaces, which is more comprehensive. Implementation 1
The Code is as follows:
String. prototype. trim = function (){Return this.
Many languages have specialized functions or methods to delete spaces at the beginning and end of a string, such as chomp of Perl and strip of Python. Then JavaScript does not seem to have similar functions, which are not mentioned in some manuals.
2 Requirements for today's reply box entry limit:
1, text content can not be all spaces, with this regular/^s*$/2, delete consecutive spaces, is this regular/s+/g
The following are common requirements codes
The code is as follows
Implementation 1Copy codeThe Code is as follows:String. prototype. trim = function (){Return this. replace (/^ \ s */, ''). replace (/\ s * $ /,'');} It looks pretty bad. I used two regular expressions to replace it. The actual speed is amazing,
JavaScript regular expression syntax and Examples
JavaScript Regular Expression
1. To use a JS regular expression, you must first understand the common symbols of the JS regular expression, such:
/... /
Indicates the start and end of a
Writing maintainable object-oriented (OO) JavaScript would save you, and make your popular. Don ' t believe me? Odds are that either you or someone else would come back and work with your code. Making as painless an experience as possible'll save
JavaScript: Common JavaScript detection scripts. Javascript tutorial *
-------------------------------------------------------------------------------
File Name: check. js
Note: JavaScript scripts are used to check the input data of the webpage
ArticleDirectory
Iv. html Functions
5. modify template Variables
Auto: http://speedphp.com/post/smarty-advanced.html
Smarty Chinese hand NLP http://www.hbcms.com/main/smarty/
Smarty template engine full tutorial
The
In the Learning Web page of the form validation, by the way to learn the regular expressionFound a relatively complete resources on the Internet, a little bit of typesetting
Copy Code code as follows:
Check whether it is a valid real
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.