validators.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*App.Validate.form = function(values){
  2. if(values.IP_ADDRESS == '') {
  3. return alert('Not correct ip');
  4. }
  5. return true;
  6. }*/
  7. App.Validate.Is = {
  8. ip: function(object) {
  9. var ip_regexp = new RegExp(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/);
  10. return ip_regexp.test() ? false : App.i18n.getMessage('incorrect_ip');
  11. }
  12. };
  13. App.Validate.form = function(world, elm)
  14. {
  15. var form_valid = true;
  16. App.Env.FormError = [];
  17. $(elm).find('select, input, textarea').each(function(i, field)
  18. {
  19. if ($.inArray($(field).attr('name'), ['target', 'source', 'save']) != -1) {
  20. //return; // pass
  21. }
  22. else {
  23. if ($(field).val().trim() == '') {
  24. App.Env.FormError.push($(field).attr('name') + ' is required');
  25. form_valid = false;
  26. }
  27. }
  28. });
  29. return form_valid;
  30. }
  31. App.Validate.displayFormErrors = function(world, elm)
  32. {
  33. var errors_tpl = '';
  34. $(App.Env.FormError).each(function(i, error)
  35. {
  36. var tpl = App.Templates.get('error_elm', 'general');
  37. tpl.set(':ERROR', error);
  38. errors_tpl += tpl.finalize();
  39. });
  40. var ref = $('.form-error', elm);
  41. ref.removeClass('hidden');
  42. ref.html(errors_tpl);
  43. }