JS中创建ValidatePwd 变量,内容如下:
- var ValidatePwd = {
- Pwd : {
- color: ['#E6EAED', '#AC0035', '#FFCC33', '#639BCC', '#246626'],
- text: ['太短', '弱', '一般', '很好', '极佳']
- },
- Result : 0,
- Evaluate : function(word) {
- if (word == "") {
- this.Result = 0;
- }
- else if (word.length < 6) {
- this.Result = 1;
- }
- else {
- this.Result = word.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
- }
- $("#pwd_check_message").text(this.Pwd.text[this.Result]);
- $("#pwd_check_message").css('color',this.Pwd.color[this.Result]);
- }
- }
调用方法:
- jQuery(function($) {
- $("#pwd_check_message").keydown(function(){
- ValidatePwd.Check($(this).val());
- });
- });