Created
October 11, 2016 12:43
-
-
Save freewayz/d287d48547112870478286eedc16331d to your computer and use it in GitHub Desktop.
Revisions
-
freewayz created this gist
Oct 11, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ var myResponse = {"start_date":["A valid integer is required."], "end_date":["A valid integer is required."], "commite":["Require commite."]} //iterate over the serializer error message for (var prop in myResponse) { var errorValue = myResponse[prop]; //test if the current prop has an _ in it string value var _pattern = /_/; if (_pattern.test(prop)) { //split the string based on the _ and join the string based with a spacke prop = prop.split('_').join(' '); } //capitalize the prop prop = prop.replace(/\b\w/g, function(s) { return s.toUpperCase(); }); var errorMessage = prop.concat(" ", errorValue); console.log(errorMessage); }