-
-
Save imCoding/8899627 to your computer and use it in GitHub Desktop.
Revisions
-
coomsie revised this gist
Aug 10, 2011 . 1 changed file with 187 additions and 79 deletions.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 @@ -1,24 +1,21 @@ //UI for valiation function validationMessages() { //*** 'me' acts as an alias that can be used within the methods var me = this; var imgPath=Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,"images/bubble.png"); validationMessages.totalErrors =0; validationMessages.reqdfieldsRemaining=0; this.messageWin = Titanium.UI.createWindow({ height: 50, width:310, top:40, touchEnabled:false, visible:true, zIndex: 999 }); this.valView = Titanium.UI.createView({ @@ -32,7 +29,7 @@ function validationMessages(){ backgroundImage: imgPath.nativePath //left:35 }); this.valLabel = Titanium.UI.createLabel({ text:'Missing or error in field (see red text)', color:'#fff', @@ -48,27 +45,32 @@ function validationMessages(){ }); this.valView.add(this.valLabel); this.messageWin.add(this.valView); this.anim_out = Titanium.UI.createAnimation(); this.anim_out.opacity=0; this.anim_out.duration = 4000; //function to display view validationMessages.prototype.displayValErr = function displayValErr(errMsg) { if(errMsg !=='' && errMsg !== undefined && errMsg !== null){ this.valLabel.text = errMsg; }else{ //default this.valLabel.text = 'Missing or error in field (see red text)'; } this.valView.opacity = 1.0; this.valView.visible = true; this.valView.show(); this.messageWin.open(); this.valView.animate(this.anim_out); // setTimeout(function() // { // //for fading out error tip and closing // this.valView.hide(); // //messageWin.close({opacity:0,duration:500}); // },4000); } } @@ -87,7 +89,7 @@ function isInteger(val) { } //function to test double **** maynot be correct *** function isDouble(val) { var re = new RegExp("[0-9.]"); Titanium.API.debug('isDouble:' + re.test(val)); return re.test(val); @@ -96,7 +98,7 @@ function isDouble(val){ function isNumber(val) { // REAL NUMBERS var re = new RegExp("/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/"); Titanium.API.debug('isNumber:' + re.test(val)); return re.test(val); } //test for real val @@ -162,73 +164,179 @@ function isWithinMaxChars(val, max) { } } var rules = {}; function setValidationRules(val) { rules = val; } //get valid rule from rules of field obj function getRule(id) { var r; for (var i = rules.length - 1; i >= 0; i--) { ///Ti.API.debug('rule' + i + rules[i]); if (rules[i].hasOwnProperty(id)) r = rules[i][id]; //use bracket notatio when dynamic }; return r; } function checkValidation(obj , fieldid) { var isValid=null; Ti.API.debug('fieldid'+fieldid); if(fieldid === undefined) fieldid = obj.id; var objRule = getRule(fieldid) //get rule for object //if no rule then do nothing if (objRule !== undefined) { Ti.API.debug('the rules' + objRule); for(var key in objRule) { Ti.API.debug(key); } Titanium.API.info('checking validation'); //clear validation obj.color = obj.validation.color; //keep record of validation colors if(!obj.validation.color) { obj.validation.color = obj.color; obj.validation.backgroundColor = obj.backgroundColor; } //set valuation highlight effect function setEffect(obj,isOff, errMsg) { if (isValid===false) { return false; } else { if(!isOff) { if (obj.color !== 'undefined') { obj.color = 'Red'; obj.backgroundColor = 'Red'; } isValid = false; if (obj.errMsg ===''){ obj.errMsg = errMsg; } } if(isOff) { if (obj.color !== 'undefined') { obj.color = obj.validation.color; obj.backgroundColor = obj.validation.backgroundColor; } isValid = true; if (obj.errMsg !== undefined){ obj.errMsg = ''; } } } return isOff; }; //run engine check if field of the whole form validationEngine(obj, objRule); function validationEngine(obj , objRule) { //check if reqd if(objRule.reqd) { setEffect(obj,isPresent(obj.value),'Value is required'); }; ///validation checks only if Value Present if(isPresent(obj.value)) { //check for double value if(objRule.isdouble) { setEffect(obj,isDouble(obj.value),'Value must be an number'); }; //check if need integer if(objRule.isinteger) { setEffect(obj,isInteger(obj.value),'Value must be an whole number'); // if (!setEffect(obj,isInteger(obj.value))) // obj.value = removeLastEntry(obj.value); }; //check if need min if(objRule.minchars) { setEffect(obj,isMinChars(obj.value,objRule.minchars),'Value under min character(s)'); }; //check if max if(objRule.maxchars) { setEffect(obj,isWithinMaxChars(obj.value,objRule.maxchars),'Value over the max character(s)'); // removed next cos the check still returns false .... // if(!isWithinMaxChars(obj.value,obj.validation.maxchars)) // { // obj.value = removeLastEntry(obj.value); // checkValidation(obj); // } }; //check within range if(objRule.range) { setEffect(obj,isWithinRange(obj.value,objRule.range.min,objRule.range.max),'Value is not within the range'); }; }; }; }; //if rule Ti.API.info('isValid:' + isValid); return isValid; }; // // //test valid email address => returns bool // function isValidEmail(emailAddress) { // var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ // return re.test(emailAddress); // } // // // //test is alpha // function isAlpha(val) { // var re = /^[a-z ._-]+$/i // return re.test(val); // } // // //test alphas numercial // function isAlphaNum(val) { // var re = /^[a-z0-9 ._-]+$/i // return re.test(val); // } // //test for phone // function isPhone(val) { // var re = /^[\d\s ().-]+$/ // return re.test(val); // } // // //test for url // function isUrl(val) { // var re = /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*$/i // return re.test(val); // } //validation model var validator = { messages: { isinteger: { eval: "Value must be an integer" }, isdouble: { eval: "Value must be an integer" }, minchars: { eval: "Value doesnt meet the min character(s) required" }, maxchars: { eval: "Value doesnt meet the max character(s) required" }, maxrange: { eval: "Value is more the max allowed" }, minrange: { eval: "Value is less the min allowed" } } }; ///end of function -
coomsie revised this gist
Jun 7, 2011 . 1 changed file with 102 additions and 181 deletions.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 @@ -1,39 +1,76 @@ //UI for valiation function validationMessages(){ //*** 'me' acts as an alias that can be used within the methods var me = this; var imgPath=Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,"images/bubble.png"); validationMessages.totalErrors =0; validationMessages.reqdfieldsRemaining=0; this.messageWin = Titanium.UI.createWindow({ height: 50, width:310, top:40, touchEnabled:false, visible:true, zIndex: 999, orientationModes : [ Titanium.UI.PORTRAIT ] }); this.valView = Titanium.UI.createView({ width:310, height:50, //backgroundColor:'Red', //borderRadius:10, opacity:1.0, touchEnabled:false, visible:false, backgroundImage: imgPath.nativePath //left:35 }); this.valLabel = Titanium.UI.createLabel({ text:'Missing or error in field (see red text)', color:'#fff', width:300, height:50, top:2, font: { fontFamily:'Helvetica Neue', fontSize:16, fontWeight:'bold' }, textAlign:'center' }); this.valView.add(this.valLabel); this.messageWin.add(this.valView); this.anim_out = Titanium.UI.createAnimation(); this.anim_out.opacity=0; this.anim_out.duration = 4000; //function to display view validationMessages.prototype.displayValErr = function displayValErr() { this.valView.opacity = 1.0; this.valView.visible = true; this.valView.show(); this.messageWin.open(); this.valView.animate(this.anim_out); // setTimeout(function() // { // //for fading out error tip and closing // this.valView.hide(); // //messageWin.close({opacity:0,duration:500}); // },4000); } } //test is Valid Number => returns bool function isValidNumber(val) { @@ -49,6 +86,19 @@ function isInteger(val) { return re.test(val); } //function to test double **** maynot be correct *** function isDouble(val){ var re = new RegExp("[0-9.]"); Titanium.API.debug('isDouble:' + re.test(val)); return re.test(val); } function isNumber(val) { // REAL NUMBERS var re = new RegExp("/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/"); Titanium.API.debug('isNumber:' + re.test(val)); return re.test(val); } //test for real val function isReal(val) { var re =/^[-+]?\d*\.?\d+$/; @@ -119,20 +169,23 @@ function checkValidation(obj) { obj.color = obj.validation.color; //keep record of validation colors if(!obj.validation.color){ obj.validation.color = obj.color; obj.validation.backgroundColor = obj.backgroundColor; } //set valuation highlight effect function setEffect(obj,isOff) { if (isValid===false) { return false; } else { if(!isOff) { obj.color = 'Red'; obj.backgroundColor = 'Red'; isValid = false; } if(isOff) { obj.color = obj.validation.color; obj.backgroundColor = obj.validation.backgroundColor; isValid = true; } } @@ -148,21 +201,27 @@ function checkValidation(obj) { if(isPresent(obj.value)) { //check for double value if(obj.validation.isdouble) { setEffect(obj,isDouble(obj.value)); }; //check if need integer if(obj.validation.isinteger) { setEffect(obj,isInteger(obj.value)); // if (!setEffect(obj,isInteger(obj.value))) // obj.value = removeLastEntry(obj.value); }; //check if need min if(obj.validation.minchars) { setEffect(obj,isMinChars(obj.value,obj.validation.minchars)); }; //check if max if(obj.validation.maxchars) { setEffect(obj,isWithinMaxChars(obj.value,obj.validation.maxchars)); // removed next cos the check still returns false .... // if(!isWithinMaxChars(obj.value,obj.validation.maxchars)) // { // obj.value = removeLastEntry(obj.value); // checkValidation(obj); // } }; //check within range if(obj.validation.range) { @@ -172,142 +231,4 @@ function checkValidation(obj) { Ti.API.info('isValid:' + isValid); return isValid; }; -
coomsie revised this gist
May 12, 2011 . 1 changed file with 284 additions and 117 deletions.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 @@ -1,146 +1,313 @@ //UI for valiation var imgPath=Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,"images/bubble.png"); var valView = Titanium.UI.createView({ width:205, height:30, backgroundColor:'Red', borderRadius:10, opacity:0.7, touchEnabled:false, visible:false, //backgroundImage: "images/bubble.png", top:2, left:50 }); Ti.API.info(valView.backgroundImage); var valLabel = Titanium.UI.createLabel({ text:'Error in field (see red text)', color:'#fff', width:205, height:'auto', font: { fontFamily:'Helvetica Neue', fontSize:13, fontWeight:'bold' }, textAlign:'center' }); valView.add(valLabel); var anim_out = Titanium.UI.createAnimation(); anim_out.opacity=0; anim_out.duration = 4000; //test is Valid Number => returns bool function isValidNumber(val) { var re=/^[-+]?\d+(\.\d+)?$/; Titanium.API.debug('isValidNumber:' + re.test(val)); return re.test(val); }; //test for integer function isInteger(val) { var re= /^[-+]?\d+$/; Titanium.API.debug('isInteger:' + re.test(val)); return re.test(val); } //test for real val function isReal(val) { var re =/^[-+]?\d*\.?\d+$/; Titanium.API.debug('isReal:' + re.test(val)); return re.test(val); } function removeLastEntry(val) { Titanium.API.debug('removeLastEntry:'); return val.slice(0,val.toString().length-1); }; //test for empty // check to see if input is whitespace only or empty function isEmpty( val ) { if ( null === val || "" === val ) { return true; } else { return false; } } //test if reqd function isPresent(val) { var re = /[^.*]/; Titanium.API.debug('isPresent:' + re.test(val)); return re.test(val); } //check for value in range // check to see if value is within min and max function isWithinRange(val, min, max) { if (val >= min && val <= max) { Titanium.API.debug('isWithinRange:true'); return true; } else { Titanium.API.debug('isWithinRange:false'); return false; } } // check to see if value is within min chars function isMinChars(val, min) { if (val.toString().length >= min) { Titanium.API.debug('isMinChars:true'); return true; } else { Titanium.API.debug('isMinChars:false'); return false; } } // check to see if value is within max chars function isWithinMaxChars(val, max) { if (val.toString().length <= max) { Titanium.API.debug('isWithinMaxChars:true'); return true; } else { Titanium.API.debug('isWithinMaxChars:false'); return false; } } function checkValidation(obj) { var isValid=null; Titanium.API.info('checking validation'); //clear validation obj.color = obj.validation.color; //keep record of validation colors if(!obj.validation.color) obj.validation.color = obj.color; //set valuation highlight effect function setEffect(obj,isOff) { if (isValid===false) { return false; } else { if(!isOff) { obj.color = 'Red'; isValid = false; } if(isOff) { obj.color = obj.validation.color; isValid = true; } } return isOff; }; //check if reqd if(obj.validation.reqd) { setEffect(obj,isPresent(obj.value)); }; ///validation checks only if Value Present if(isPresent(obj.value)) { //check for double value if(obj.validation.isdouble) { setEffect(obj,isReal(obj.value)); } //check if need integer if(obj.validation.isinteger) { if (!setEffect(obj,isInteger(obj.value))) obj.value = removeLastEntry(obj.value); }; //check if need min if(obj.validation.minchars) { setEffect(obj,isMinChars(obj.value,obj.validation.minchars)); }; //check if max if(obj.validation.maxchars) { if(!setEffect(obj,isWithinMaxChars(obj.value,obj.validation.maxchars))) obj.value = removeLastEntry(obj.value); }; //check within range if(obj.validation.range) { setEffect(obj,isWithinRange(obj.value,obj.validation.range.min,obj.validation.range.max)); }; }; Ti.API.info('isValid:' + isValid); return isValid; }; /// UNTEST STUFF BELOW // //test valid date => returns bool // function isValidDate (dateStr, format) { // if (format == null) { // format = "MDY"; // } // format = format.toUpperCase(); // if (format.length != 3) { // format = "MDY"; // } // if ( (format.indexOf("M") == -1) || (format.indexOf("D") == -1) || _ // (format.indexOf("Y") == -1) ) { // format = "MDY"; // } // if (format.substring(0, 1) == "Y") { // If the year is first // var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ // var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ // } else if (format.substring(1, 2) == "Y") { // If the year is second // var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/ // var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/ // } else { // The year must be third // var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/ // var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/ // } // // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail // if ( (reg1.test(dateStr) == false) && (reg2.test(dateStr) == false) ) { // return false; // } // var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was // // Check to see if the 3 parts end up making a valid date // if (format.substring(0, 1) == "M") { // var mm = parts[0]; // } else _ // if (format.substring(1, 2) == "M") { // var mm = parts[1]; // } else { // var mm = parts[2]; // } // if (format.substring(0, 1) == "D") { // var dd = parts[0]; // } else _ // if (format.substring(1, 2) == "D") { // var dd = parts[1]; // } else { // var dd = parts[2]; // } // if (format.substring(0, 1) == "Y") { // var yy = parts[0]; // } else _ // if (format.substring(1, 2) == "Y") { // var yy = parts[1]; // } else { // var yy = parts[2]; // } // if (parseFloat(yy) <= 50) { // yy = (parseFloat(yy) + 2000).toString(); // } // if (parseFloat(yy) <= 99) { // yy = (parseFloat(yy) + 1900).toString(); // } // var dt = new Date(parseFloat(yy), parseFloat(mm)-1, parseFloat(dd), 0, 0, 0, 0); // if (parseFloat(dd) != dt.getDate()) { // return false; // } // if (parseFloat(mm)-1 != dt.getMonth()) { // return false; // } // return true; // } // // //test valid email address => returns bool // function isValidEmail(emailAddress) { // var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ // return re.test(emailAddress); // } // // // //test is alpha // function isAlpha(val) { // var re = /^[a-z ._-]+$/i // return re.test(val); // } // // //test alphas numercial // function isAlphaNum(val) { // var re = /^[a-z0-9 ._-]+$/i // return re.test(val); // } // //test for phone // function isPhone(val) { // var re = /^[\d\s ().-]+$/ // return re.test(val); // } // // //test for url // function isUrl(val) { // var re = /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*$/i // return re.test(val); // } // //test valid time => return bool // // valid entries 12:25 & 12:25PM // function isValidTime(value) { // var hasMeridian = false; // var re = /^\d{1,2}[:]\d{2}([:]\d{2})?( [aApP][mM]?)?$/; // if (!re.test(value)) { // return false; // } // if (value.toLowerCase().indexOf("p") != -1) { // hasMeridian = true; // } // if (value.toLowerCase().indexOf("a") != -1) { // hasMeridian = true; // } // var values = value.split(":"); // if ( (parseFloat(values[0]) < 0) || (parseFloat(values[0]) > 23) ) { // return false; // } // if (hasMeridian) { // if ( (parseFloat(values[0]) < 1) || (parseFloat(values[0]) > 12) ) { // return false; // } // } // if ( (parseFloat(values[1]) < 0) || (parseFloat(values[1]) > 59) ) { // return false; // } // if (values.length > 2) { // if ( (parseFloat(values[2]) < 0) || (parseFloat(values[2]) > 59) ) { // return false; // } // } // return true; // } // -
coomsie revised this gist
May 5, 2011 . 1 changed file with 1 addition and 1 deletion.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 @@ -36,7 +36,7 @@ function isEmpty( val ) { //test if reqd function isPresent(val) { var re = /[^.*]/; Titanium.API.debug('isPresent:' + re.test(val)); return re.test(val); } -
coomsie created this gist
May 5, 2011 .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,146 @@ //test is Valid Number => returns bool function isValidNumber(val) { var re=/^[-+]?\d+(\.\d+)?$/; Titanium.API.debug('isValidNumber:' + re.test(val)); return re.test(val); }; //test for integer function isInteger(val) { var re= /^[-+]?\d+$/; Titanium.API.debug('isInteger:' + re.test(val)); return re.test(val); } //test for real val function isReal(val) { var re =/^[-+]?\d*\.?\d+$/; Titanium.API.debug('isReal:' + re.test(val)); return re.test(val); } function removeLastEntry(val) { Titanium.API.debug('removeLastEntry:'); return val.slice(0,val.toString().length-1); }; //test for empty // check to see if input is whitespace only or empty function isEmpty( val ) { if ( null === val || "" === val ) { return true; } return false; } //test if reqd function isPresent(val) { var re = /[^.*]/ Titanium.API.debug('isPresent:' + re.test(val)); return re.test(val); } //check for value in range // check to see if value is within min and max function isWithinRange(val, min, max) { if (val >= min && val <= max) { Titanium.API.debug('isWithinRange:true'); return true; } else { Titanium.API.debug('isWithinRange:false'); return false; } } // check to see if value is within min chars function isMinChars(val, min) { if (val.toString().length >= min) { Titanium.API.debug('isMinChars:true'); return true; } else { Titanium.API.debug('isMinChars:false'); return false; } } // check to see if value is within max chars function isWithinMaxChars(val, max) { if (val.toString().length <= max) { Titanium.API.debug('isWithinMaxChars:true'); return true; } else { Titanium.API.debug('isWithinMaxChars:false'); return false; } } var isValid=null; function checkValidation(obj) { Titanium.API.info('checking validation'); //clear validation obj.color = obj.validation.color; //keep record of validation colors if(!obj.validation.color) obj.validation.color = obj.color; //set valuation highlight effect function setEffect(obj,isOff) { if (isValid===false) { return false; }else { if(!isOff) obj.color = 'Red'; isValid = false; if(isOff) obj.color = obj.validation.color; isValid = true; } return isOff; }; //check if reqd if(obj.validation.reqd) { setEffect(obj,isPresent(obj.value)); }; ///validation checks only if Value Present if(isPresent(obj.value)) { //check for double value if(obj.validation.isdouble) { if (!setEffect(obj,isReal(obj.value))) setEffect(obj,isReal(obj.value)); } //check if need integer if(obj.validation.isinteger) { if (!setEffect(obj,isInteger(obj.value))) obj.value = removeLastEntry(obj.value); }; //check if need min if(obj.validation.minchars) { setEffect(obj,isMinChars(obj.value,obj.validation.minchars)); }; //check if max if(obj.validation.maxchars) { if(!setEffect(obj,isWithinMaxChars(obj.value,obj.validation.maxchars))) obj.value = removeLastEntry(obj.value); }; //check within range if(obj.validation.range) { setEffect(obj,isWithinRange(obj.value,obj.validation.range.min,obj.validation.range.max)); }; }; Ti.API.info('isValid:' + isValid); };