1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary Timecode Field Validator 5 */ 6 7 goog.provide('Banana.Controls.Decorators.TimecodeFieldValidator'); 8 9 goog.require('Banana.Controls.Decorators.Validator'); 10 11 /** @namespace Banana.Controls.Decorators.TimecodeFieldValidator */ 12 namespace('Banana.Controls.Decorators').TimecodeFieldValidator = Banana.Controls.Decorators.Validator.extend( 13 /** @lends Banana.Controls.Decorators.TimecodeFieldValidator.prototype */ 14 { 15 16 /** 17 * Creates a timecode field validator 18 * 19 * Matches date, time(code) or date and time(code) 20 * Matches DD-MM-YYYY where 00 < DD < 32, 00 < MM < 13, 1900 =< YYYY < 3000 21 * Matches HH:MM:SS:FF or HH:MM:SS where 00 =< HH < 24, 00 =< MM/SS < 60, and 00 =< FF < 25 22 * 23 * @param {Banana.Controls.InputControl} controlToValidate 24 * @constructs 25 * @extends Banana.Controls.Decorators.Validator 26 */ 27 init : function(controlToValidate) 28 { 29 this._super(controlToValidate); 30 31 this.showIndicator = false; 32 }, 33 34 /** 35 * @param {boolean} r 36 * if true we need to pass data in order to pass the validation. false means that we can exclude data 37 * in order to pass validation 38 */ 39 setRequired : function(r) 40 { 41 this.required = r; 42 43 this.showIndicator = r; 44 return this; 45 }, 46 47 /** 48 * @override 49 * @param {String} data 50 */ 51 validateData : function(data) 52 { 53 if (!data && !this.required) 54 { 55 return true; 56 } 57 else if (!data) 58 { 59 return false; 60 } 61 62 // Matches date, time(code) or date and time(code) 63 // Matches DD-MM-YYYY where 00 < DD < 32, 00 < MM < 13, 1900 =< YYYY < 3000 64 // Matches HH:MM:SS:FF or HH:MM:SS where 00 =< HH < 24, 00 =< MM/SS < 60, and 00 =< FF < 25 65 if (data.match(/^((0?[1-9]|[12][0-9]|3[01])[\- \/.](0?[1-9]|1[012])[\- \/.](19|20)?[0-9]{2})? ?((2[0-3]|[0-1][0-9]):(5[0-9]|[0-4][0-9]):(5[0-9]|[0-4][0-9])(:(2[0-4]|[0-1][0-9]))?)?$/)) 66 { 67 return true; 68 } 69 return false; 70 }, 71 72 /** 73 * @override 74 * @return {String} 75 */ 76 getInfoText : function() 77 { 78 return 'Valid timecode required'; 79 } 80 });