utils.js files; Backup of some common methods

Source: Internet
Author: User

Some common ways to back up:

function_ (value) {Value= ' 0 ' +value; returnValue.substr (value.length-2);} Date.prototype.format=function(split) {split= Split | | ""; if(split = = = ' time ')) {        return_( This. GetHours ()) + ': ' + _ ( This. getminutes ()) + ': ' + _ ( This. getseconds ());/*return time: minutes: Seconds*/    } Else {        varmonth = This. GetMonth () + 1; Month= Month < 10? "0" +Month:month; varDay = This. GetDate (); Day= Day < 10? "0" +Day:day; return  This. getFullYear () + split + month + split + day;/*Return Month Day*/}}date.prototype.time=function() {    varhour = This. GetHours (); varminute = This. getminutes (); Hour= Hour < 10? "0" +Hour:hour; Minute= Minute < 10? "0" +Minute:minute; returnHour + ":" + minute;/*return: Minutes*/}date.prototype.adddays=function(n) {return NewDate ( This. SetDate ( This. GetDate () +n));;D Ate.prototype.addMonths=function(n) {return NewDate ( This. Setmonth ( This. GetMonth () +n));}; Array.prototype.max=function() {    returnMath.max.apply (NULL, This);} Array.prototype.min=function() {    returnMath.min.apply (NULL, This);} Array.prototype.maxVal=function() {    return  This. sort () [ This. length-1];} Array.prototype.minVal=function() {    return  This. sort () [0];} Array.prototype.update=function(value) {varpos = $.inarray (Value, This); if(pos = = =-1) {         This. push (value); } Else {         This. Splice (POS, 1); }    return  This;} String.prototype.format=function(split) {split= Split | | ‘‘; varvalue; if( This. IndexOf ('/')!==-1) {Value= This. replace (/\//g, split); } Else if( This. IndexOf ('-')!==-1) {Value= This. replace (/-/g, split); } Else{Value= This. substr (0, 4) + split + This. substr (4, 2) + split + This. substr (6); }    if(Split = = ' Date ') {        vararr =Value.split (split); Value=NewDate (Arr[0], parseint (arr[1])-1, arr[2])    }    if(split = = ' TimeStamp ')) {        vararr =Value.split (split); Value=NewDate (Arr[0], parseint (arr[1])-1, arr[2]) value=Value.gettime (); }    returnvalue;} String.prototype.decimal=function() {    varvalue; if( This. IndexOf ('. ') = =-1) {Value= This+ '. 00 '; } Else if( This. Split (".") [1].length = 1) {Value= This+ ' 0 '; } Else{Value= This+ '; }    returnvalue;}varA ={Service: {get:function(URL, data, success, error) {$.ajax ({url:url, type:"GET", DataType:"JSON", Data:data|| "", Cache:false, Success:function(Result) {Success&&success (result); }, Error:function(XHR) {varindex = Layer.alert (xhr.responsejson[0].content, {title:Prompted                    }, function() {                        if(Xhr.status = = 401) {layer.close (index); //to fetch the Exit function of a parent pageSelf.parent.window.quit (); } Else{layer.close (index);                    }                    }); Error&&error (); }}), Post:function(URL, data, success, error) {Data=json.stringify (data); $.ajax ({url:url, type:"POST", DataType:"JSON", Data:data, cache:false, ContentType:"Application/json", Success:function(Result) {Success&&success (result); }, Error:function(XHR) {if(Xhr.status = = 401) {                        varindex = Layer.alert (xhr.responsejson[0].content, {title:Prompted                        }, function() {layer.close (index);                        Self.parent.window.quit ();                    }); } Else if(Xhr.status = = 404) {                        varindex = Layer.alert (' Access error or internal server error ', {title:Prompted                        }, function() {layer.close (index);                    }); } Else{layer.msg (xhr.responsejson[0].content, {time:2000                        }); } Error&&error (); })}, Jsonp:function(URL, data, callback) {$.ajax ({url:url, DataType:"Jsonp", Data:data, Jsonp:"Callback", Success:function(Result) {callback (result); }, timeout:3000            }); }}, params:function() {        varparams = decodeURIComponent (Window.location.search). substr (1); if(Params.indexof (' = ')!==-1) {            vararr = Params.split (' & '); varJSON = {};  for(vari = 0; i < arr.length; i++) {                vart = arr[i].split (' = ')); json[t[0]] = t[1]; }            returnJSON; } Else {            returnparams; }}, Hash:function() {        varhash = decodeURIComponent (Window.location.hash). substr (1); vararr = Hash.split ('-'); returnArr[1]; },    //string//Get//Last oneGERSTR:function(str) {vars = '; S= Str.charat (str.length-1); returns; },    //string//Remove//LastCUTSTR:function(str) {vars = '; S= str.substring (0, Str.length-1); returns; }, Express: {mobile: {exp:/^[1][3-8]\d{9}$/, message:"Please enter the correct mobile phone number"}, Password: {exp:/^[[email protected]]+$/, message:"Passwords are made up of letters, numbers, underscores, or @"}, Enterprisename: {exp:/^[a-za-z\u4e00-\u9fa5 () () _]+$/, message:"Enterprise name can only be entered in English, underline or parentheses"}, License: {Exp:/^[0-9a-za-z\-]+$/, message:"Business license number only allows digital English horizontal line"}, Address: {Exp:/^[0-9a-za-z\u4e00-\u9fa5# () () _-]+$/, message:"Company location can only contain English, Chinese, numerals, underscores, dashes, brackets, and # # #"}, UserName: {exp:/^[a-za-z\u4e00-\u9fa5]+$/, message:"Name can only be in Chinese and English format"}, Fixedtel: {exp:/^[0-9\s,,, \-]*$/, message:"Office phone can only contain numbers comma comma horizontal lines and spaces"}, JobName: {exp:/^[0-9a-za-z\u4e00-\u9fa5 () () _]+$/, message:"Position name can only contain Chinese and English numerals underlined or parentheses"}, Recruitnum: {exp:/^\+? [1-9] [0-9]*$/, message:"The number of recruits can only be 0 positive integers ~"}, Salary: {Exp:/^ ([1-9]\d*|0) (\.\d{1,2})? $/, message:"Compensation can be a positive integer or contain two decimal places"}, Height: {exp:/^\d{2,3}$/, message:"Height can only be a 2-3-bit integer"}, Email: {Exp:/^ (\w-*\.*) [email protected] (\w-?) + (\.\w{2,}) +$/, message:"Please check the mailbox format"}, Money: {Exp:/^ ([1-9]\d*) |\d) (\.\d{1,2})? $/, message:"Please enter the correct payment amount"}, Regcode: {exp:/^\d{4}$/, message:"Please enter the correct verification Code"        }    }}
View Code

utils.js files; Backup of some common methods

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.