Common JS Verification Code

Source: Internet
Author: User
Tags date1 rtrim

Common JS Verification Code

// Whether the verification function isempty (s) {var lll = trim (s); If (lll = NULL | lll. length = 0) return true; elsereturn false ;}
// Delete the space function ltrim (STR) {If (Str. length = 0) Return (STR); else {var idx = 0; while (Str. charat (idx ). search (/\ s/) = 0) idx ++; Return (Str. substr (idx ));}}
// Delete the space function rtrim (STR) {If (Str. length = 0) Return (STR); else {var idx = Str. length-1; while (Str. charat (idx ). search (/\ s/) = 0) idx --; Return (Str. substring (0, idx + 1 ));}}
// Delete the space between the left and right sides of the string function trim (STR) {return (rtrim (ltrim (STR )));}
/* Date comparison */function comparedate (date1, date2) {If (TRIM (date1) = trim (date2) return 0; If (TRIM (date1)> trim (date2) return 1; if (TRIM (date1) <trim (date2) Return-1 ;}
// Check whether emailfunction isemail (EML) {If (TRIM (EML )! = '') {Var Re = new Regexp (" @ [\ W] + (\\. [\ W] +) + {1} quot;); Return (Re. test (EML);} else return (true );}
// Whether the phone number is function istel (TEL) {var charcode; For (VAR I = 0; I <Tel. length; I ++) {charcode = Tel. charcodeat (I); If (charcode <48 & charcode! = 45 | charcode> 57) return false;} return true ;}
// Check whether it is a real number function isnumber (Num) {var Re = new Regexp ("^ -? [\ D] * \.? [\ D] * {1} quot;); If (Re. Test (Num) Return (! Isnan (parsefloat (Num); elsereturn (false );}
// Check whether it is an integer function isinteger (Num) {var Re = new Regexp ("^ -? [\ D] * {1} quot;); If (Re. Test (Num) Return (! Isnan (parseint (Num); elsereturn (false );}
// Check whether it is a combination of numbers and letters and is a 4-6-digit function isnumorletters (STR) {var Re = new Regexp (/^ [a-zA-Z0-9] {} $ /); if (Re. test (TRIM (STR) Return (true); else return (false );}

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.