define(function(require) {
'use strict';
return {
init: function() {
var Strategy = require('strategy/strategy'), telValidator = require('strategy/telValidator'), emailValidator = require('strategy/emailValidator'), validator;
validator = new Strategy();
console.log(validator.selectValidator(telValidator).validate(12345678911));
console.log(validator.selectValidator(emailValidator).validate('phamngoctuong@gmail.com'));
}
};
});
define(function() {
'use strict';
var Validator = function() {};
Validator.prototype.selectValidator = function(validator) {
this.validator = validator;
return this;
};
Validator.prototype.validate = function(value) {
if (this.validator) {
return this.validator.validate(value);
}
throw ('No validator selected');
};
return Validator;
});
define(function() {
'use strict';
return {
validate: function(value) {
return value.indexOf('@') !== -1;
}
};
});
define(function() {
'use strict';
return {
validate: function(value) {
return (/^[0-9]{11}$/g).test(value);
}
}
});