/* * To change this template, choose Tools | Templates * and open the template in the editor. */ $.fn.uaInteger = function(options) { options = $.extend({ bMandatory: true , bToolTip: true , //true, TYPE_OPTIONAL, TYPE_IGNORE bDisabled: false , bReadOnly: false , defaultValue: '' , hint: '' , iMinValue: 0 , //no min value iMaxValue: 100 //no max value }, options); options.iMinChars = (options.iMinValue+ '').length; options.iMaxChars = (options.iMaxValue+ '').length; $.fn.extend(this, this.uaString({ bMandatory: options.bMandatory , bToolTip: options.bToolTip , bDisabled: options.bDisabled , bReadOnly: options.bReadOnly , iMinChars: options.iMinChars , iMaxChars: options.iMaxChars , defaultValue: options.defaultValue , hint: options.hint })); this. off(EV_CHECK_SPECIFIC_ERRORS). on(EV_CHECK_SPECIFIC_ERRORS,function(ev) { ev.stopImmediatePropagation(); $(this).trigger(EV_CLEAR_ERRORS); //optionsl & no characters? => ignore if(!$(this).val().length && !options.bMandatory) { return; };//if //no min chars ? if($(this).val().length < options.iMinChars) { $(this).trigger($.Event(EV_SET_ERROR_MSG,{uaData:{data:{msg:"This field is mandatory
You MUST have a minimum of " + options.iMinChars + " characters"}}})); return; }; if(!(new RegExp(/^(\d){1,}$/).test($(this).val().replace(/(\d),(?=\d)/g, '$1')))) { $(this).trigger($.Event(EV_SET_ERROR_MSG,{uaData:{data:{msg:"Not a properly formated number
Example: 123"}}})); return; }; //in range? if( (parseInt($(this).val()) options.iMaxValue )) { $(this).trigger($.Event(EV_SET_ERROR_MSG,{uaData:{data:{msg:"This must be a number between " + options.iMinValue + ' and '+ options.iMaxValue}}})); return; };//if }); this.getFormated = function() {//get integer with commas return $(this).val().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }; this.getUnformated = function() { return $(this).val().replace(/(\d),(?=\d)/g, '$1'); }; this.setFormated = function() { $(this).val($(this).val().replace(/\B(?=(\d{3})+(?!\d))/g, ",")); return this; }; this.setValue_Formated = function(data) {//display contents of 'val' $(this).val((data+'').replace(/\B(?=(\d{3})+(?!\d))/g, ",")); return this; }; return this; };//nkTdDtInteger