JS to determine whether the string is empty, filter the space, find the string position, and so on set of functions

Source: Internet
Author: User

This is an online collection of JS code snippet, used to determine whether the specified string is empty, filter the space on either side of a character in a string, find where the specified string starts, use the Isfloat function to determine whether a string consists of a number (int or long or float), The Isdigital function determines whether a string is composed of a number (int or long), and so on:

//The IsEmpty function determines whether a string is emptyfunctionIsEmpty (HIS) {flag=true; for(vari=0;i){if(His.charat (i)! = "") {flag=false;  Break;}}returnFlag;}//trim function to remove spaces on both sides of a stringfunctionTrim (HIS) {//Find string start positionPos_start =-1; for(vari=0;i){if(His.charat (i)! = "") {Pos_start=i; Break; }}//Find string End positionPos_end =-1; for(vari=his.length-1;i>=0;i--){if(His.charat (i)! = "") {Pos_end=i; Break; }}//the returned stringStr_return = ""if(Pos_start!=-1 && Pos_end!=-1){  for(vari=pos_start;i<=pos_end;i++) {Str_return= Str_return +His.charat (i);}}returnStr_return;} //The Isdigital function determines whether a string consists of a number (int or long)functionisdigital (str) { for(ilen=0;ilen<str.length;ilen++){if(Str.charat (Ilen) < ' 0 ' | | str.charat (ilen) > ' 9 ' ){return false;} }return true;}//The Isfloat function determines whether a string consists of a number (int or long or float)functionisfloat (str) {Flag_dec= 0 for(ilen=0;ilen<str.length;ilen++){if(Str.charat (ilen) = = '. ') {Flag_dec++;if(Flag_dec > 1)return false;ElseContinue;} if(Str.charat (Ilen) < ' 0 ' | | str.charat (ilen) > ' 9 ' ){return false;} }return true;}

JS to determine whether the string is empty, filter the space, find the string position, and so on set of functions

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.