Advertisement
Guest User

Untitled

a guest
May 29th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. var ValidatorMixin = {
  2. validate: function() {
  3. var obj = this.state[this.validationObject];
  4. var errors = {};
  5. for (var key in this.validationRules) {
  6. var rule = this.validationRules[key];
  7. if (!rule.valid(obj[key])) {
  8. errors[key] = rule.message;
  9. }
  10. }
  11.  
  12. if (Object.keys(errors).length === 0) {
  13. this.setState({errors: null});
  14. return true;
  15. } else {
  16. this.setState({errors: errors});
  17. return false;
  18. }
  19. }
  20. };
  21.  
  22. var ValidationRules = {
  23. notEmptyHtml: function(v) {
  24. v = v.replace(/<\/?[a-z]*>/g, '');
  25. v = v.replace(/&nbsp;/g, '');
  26. return !String.isEmpty(v);
  27. }
  28. };
  29.  
  30. module.exports = {
  31. mixin: ValidatorMixin,
  32. rules: ValidationRules
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement