vardata = { "username": "Zhangsan", "Password": "12345690", "Code": "ABCD" }; varValidate ={rules: {}, config: {}, msg: [], check:function(data) {vark, rule, config, checker; Rule= This. Rules; Config= This. config; This. msg.length = 0; for(kinchdata) { if(Data.hasownproperty (k)) {if(!Rule[k]) { Throw NewError ("Validate.check error, Error type:" + K + "not exist")); } Checker= This. Rules[k]; if(!checker.validate (Data[k])) { This. Msg.push (checker.msg); } } } } }; Validate.rules.username={validate:function(username) {returnUsername.length > 7; }, msg:"User name is incorrect" }; Validate.rules.password={validate:function(password) {returnPassword.length > 7}, msg:"The password is dead." }; Validate.rules.code={validate:function(code) {returnCode = = = "ABCdef"; }, msg:"The verification code is not correct" }; Validate.check (data); if(validate.msg.length) {Console.log (Validate.msg.join ("\ n")); }
JavaScript mode (iii) policy mode