Take two digits, intercept the number, ask for age, remove the space before and after

Source: Internet
Author: User

 //  Take two-digit   function   Todou (n) { if  (N < 10< Span style= "color: #000000") { return  ' 0 ' + n}  else   { return  ' + n}}  //  intercept number  function   GETN (s) { if   (s) { return  s.replace (/[^0-9\.)    /ig, "); }} 

Remove space before and after
String.prototype.trim = function () {
Return This.replace (/(^\s*) | ( \s*$)/g, ");
}

//seeking AgefunctionGetage (strbirthday) {varReturnage; varStrbirthdayarr = Strbirthday.split ("-"); varBirthyear = strbirthdayarr[0]; varBirthmonth = strbirthdayarr[1]; varBirthDay = strbirthdayarr[2]; D=NewDate (); varNowyear =d.getfullyear (); varNowmonth = D.getmonth () + 1; varNowday =d.getdate (); if(Nowyear = =birthyear) {Returnage= 0;//the same year is 0 years old}Else {        varAgediff = Nowyear-birthyear;//Years of Difference        if(Agediff > 0) {            if(Nowmonth = =birthmonth) {                varDaydiff = Nowday-birthday;//the difference between days                if(Daydiff < 0) {Returnage= AgeDiff-1; } Else{returnage=Agediff; }            } Else {                varMonthdiff = Nowmonth-birthmonth;//the difference of the month                if(Monthdiff < 0) {Returnage= AgeDiff-1; } Else{returnage=Agediff; }            }        } Else{returnage=-1;//Return-1 indicates birth date input error later than today        }    }    returnReturnage;//age of Return years}

The old driver ...

Take two digits, intercept the number, ask for age, remove the space before and after

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.