Function package landing strategy to facilitate the call

Landing strategy:
            Results packaged as a function to facilitate a direct call, after call for the true and false
            All policies need to exist in an object
var Strategy = ( function () {
        var obj = { 
           allNum: / ^ \ + $ D / , 
           allLetter: / ^ [AZ] + $ / I,
             // add additional policies for retrieving     
       } 

       // return a function 
       return  function (Val, STR) {
            return obj [STR] .test (Val); 
       } 
   }) (); 

    // bind username lose focus event 
   IPT [0] .onblur = function () {
         // get user input 
        var Val = the this .Value;
         // verify that the user name is a pure letter
        IF (Strategy (Val, 'allLetter' )) { 
            the console.log ( 'verified' ); 
        } the else { 
            the console.log ( 'authentication failure' ); 
        } 
    } 

    // bind password lost focus event 
    ipt [1]. = the onblur function () {
         // get user input 
        var Val = the this .Value;
         // authentication password is a pure digital 
        iF (Strategy (Val, 'allNum' )) { 
            the console.log ( 'verified' ); 
        } the else { 
            the console.log ( 'authentication failure' );
        }
    }

 

Guess you like

Origin www.cnblogs.com/yess/p/12158467.html