ngx-advanced-input
Version:
A simple library to allow/restrict characters when typing.
2 lines • 3.02 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define("ngx-advanced-input",["exports","@angular/core"],t):t(e["ngx-advanced-input"]={},e.ng.core)}(this,function(e,t){"use strict";var n=(i.prototype.onKeyDown=function(e){if(-1===this.specialKeys.indexOf(e.key))if("alphaWithSpace"===this.inputType)"Space"===e.code&&0===this.el.nativeElement.value.length?e.preventDefault():"Space"===e.code&&0<this.el.nativeElement.value.length?this.isSpaceEntered?e.preventDefault():this.isSpaceEntered=!0:(this.isSpaceEntered=!1,(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.regexWithSpace)&&e.preventDefault());else if("alpha"===this.inputType)37===e.keyCode||39===e.keyCode||(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.regex)&&e.preventDefault();else if("noSpace"===this.inputType)"Space"===e.code&&0===this.el.nativeElement.value.length?e.preventDefault():"Space"===e.code&&0<this.el.nativeElement.value.length?this.isSpaceEntered?e.preventDefault():this.isSpaceEntered=!0:this.isSpaceEntered=!1;else if("number"===this.inputType)(e.ctrlKey||e.metaKey)&&67==e.keyCode||(e.ctrlKey||e.metaKey)&&86==e.keyCode||37===e.keyCode||39===e.keyCode||(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.numberRegex)&&e.preventDefault();else if("strictlyNumber"===this.inputType)(e.ctrlKey||e.metaKey)&&67==e.keyCode||(e.ctrlKey||e.metaKey)&&86==e.keyCode||37===e.keyCode||39===e.keyCode||(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.strictlyNumberRegExp)&&e.preventDefault();else if("noFSpace"===this.inputType)"Space"===e.code&&0===this.el.nativeElement.value.length&&e.preventDefault();else if("alphaWithUnderscore"===this.inputType)(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.regexWithUnderScore)&&e.preventDefault();else if("numberWithColon"===this.inputType){var t;(t=this.el.nativeElement.value.concat(e.key))&&!String(t).match(this.numberWithFullColon)&&e.preventDefault()}},i.decorators=[{type:t.Directive,args:[{selector:"[advancedInput]"}]}],i.ctorParameters=function(){return[{type:t.ElementRef}]},i.propDecorators={inputType:[{type:t.Input,args:["inputType"]}],onKeyDown:[{type:t.HostListener,args:["keydown",["$event"]]}]},i);function i(e){this.el=e,this.regex=new RegExp(/^[a-zA-Z0-9]*$/),this.regexWithSpace=new RegExp(/^[a-zA-Z0-9 ]*$/),this.regexWithUnderScore=new RegExp(/^[a-zA-Z0-9_]*$/),this.numberRegex=new RegExp(/^-?([0-9]*)+(\.[0-9]*){0,1}$/g),this.numberWithFullColon=new RegExp(/^-?([0-9]*)+(\:[0-9]*){0,1}$/g),this.strictlyNumberRegExp=new RegExp(/^[0-9]*$/g),this.specialKeys=["Backspace","Tab","End","Home","Delete"],this.isSpaceEntered=!1}var a=(r.decorators=[{type:t.NgModule,args:[{declarations:[n],imports:[],exports:[n]}]}],r);function r(){}e.NgxAdvancedInputDirective=n,e.NgxAdvancedInputModule=a,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-advanced-input.umd.min.js.map