accept 2 values after decimal in angular forms
JavaScript
<input type="textbox" [(ngModel)]="InputValue" appTwoDigitDecimaNumber>import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[appTwoDigitDecimaNumber]'
})
export class TwoDigitDecimaNumberDirective {
private regex: RegExp = new RegExp(/^\d*\.?\d{0,2}$/g);
private specialKeys: Array<string> = ['Backspace', 'Tab', 'End', 'Home', '-', 'ArrowLeft', 'ArrowRight', 'Del', 'Delete'];
constructor(private el: ElementRef) {
}
@HostListener('keydown', ['$event'])
onKeyDown(event: KeyboardEvent) {
console.log(this.el.nativeElement.value);
// Allow Backspace, tab, end, and home keys
if (this.specialKeys.indexOf(event.key) !== -1) {
return;
}
let current: string = this.el.nativeElement.value;
const position = this.el.nativeElement.selectionStart;
const next: string = [current.slice(0, position), event.key == 'Decimal' ? '.' : event.key, current.slice(position)].join('');
if (next && !String(next).match(this.regex)) {
event.preventDefault();
}
}
}
Also in JavaScript:
- Title
- include javascript jquery file in html
- Category
- JavaScript
- Title
- how to check chrome version in js
- Category
- JavaScript
- Title
- add item to list javascript
- Category
- JavaScript
- Title
- iterate array in javascrpt
- Category
- JavaScript
- Title
- href back page javascript
- Category
- JavaScript
- Title
- chart.js label word wrap
- Category
- JavaScript
- Title
- duplicate encoder
- Category
- JavaScript
- Title
- eval in js
- Category
- JavaScript
- Title
- ${ js
- Category
- JavaScript
- Title
- angular two way property binding
- Category
- JavaScript
- Title
- how to add role in discord.js v12
- Category
- JavaScript
- Title
- how to use json stringify in javascript
- Category
- JavaScript
- Title
- destruct e.target.value param
- Category
- JavaScript
- Title
- Javascript change element class
- Category
- JavaScript
- Title
- express and node
- Category
- JavaScript
- Title
- c# httpclient post json stringcontent
- Category
- JavaScript
- Title
- how to add set between two date in datatable
- Category
- JavaScript
- Title
- console log all array values node
- Category
- JavaScript
- Title
- how to get mouse coordinates in javascript
- Category
- JavaScript
- Title
- HTML5 Accesskey Attribute: you may not need JavaScript to add Keyboard Shortcuts
- Category
- JavaScript
- Title
- async await catch error
- Category
- JavaScript
- Title
- append new element for each value in array d3.js
- Category
- JavaScript
- Title
- how to use reduce javascript
- Category
- JavaScript
- Title
- how to deploy react app in tomcat server
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- hide show div jquery
- Category
- JavaScript
- Title
- how run dockerfile
- Category
- JavaScript
- Title
- angular npm angular material
- Category
- JavaScript
- Title
- how to turn decimales into percents with javascript
- Category
- JavaScript
- Title
- allow cross origin node
- Category
- JavaScript
- Title
- google auth.onstatechange
- Category
- JavaScript
- Title
- how to get the last element in javascript
- Category
- JavaScript
- Title
- get and set es6
- Category
- JavaScript
- Title
- Factorial
- Category
- JavaScript
- Title
- electron new window
- Category
- JavaScript
- Title
- electron Uncaught ReferenceError: require is not defined at recorder.js:1
- Category
- JavaScript
- Title
- delete last element of array js
- Category
- JavaScript
- Title
- add set time out in jquery
- Category
- JavaScript
- Title
- array map javascript mozilla
- Category
- JavaScript
- Title
- how to make a factorial function in javascript
- Category
- JavaScript
- Title
- error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class.
- Category
- JavaScript
- Title
- how to get a random element of an array javascript
- Category
- JavaScript
- Title
- closure javascript
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- best react native animation library
- Category
- JavaScript
- Title
- how to create uuid in javascript
- Category
- JavaScript
- Title
- express how to access ajax post data
- Category
- JavaScript
- Title
- how to find out what a string ends with in javascript
- Category
- JavaScript
- Title
- how to sort array least to greatest javascript
- Category
- JavaScript
- Title
- discord js bot leave voice channel
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- he href attribute is required for an anchor to be keyboard accessible
- Category
- JavaScript
- Title
- angular @Output()
- Category
- JavaScript
- Title
- how to display image in html from json object
- Category
- JavaScript
- Title
- adding mui theme to index.js
- Category
- JavaScript
- Title
- axios file upload
- Category
- JavaScript
- Title
- if checkbox checked jquery value 1
- Category
- JavaScript
- Title
- error sending empty object express
- Category
- JavaScript
- Title
- button style in jquery datatable
- Category
- JavaScript
- Title
- javascript audio stop
- Category
- JavaScript
- Title
- install node js lts ubuntu 18.04
- Category
- JavaScript
- Title
- ajax with django
- Category
- JavaScript
- Title
- add cloudinary to gatsby javascript
- Category
- JavaScript
- Title
- casl react
- Category
- JavaScript
- Title
- fetch api javascript
- Category
- JavaScript
- Title
- how to add class to button in javascript
- Category
- JavaScript
- Title
- Exception in thread "main" org.openqa.selenium.JavascriptException:
- Category
- JavaScript
- Title
- how to check for duplicate syntax in javascript
- Category
- JavaScript
- Title
- is typescript faster than javascript
- Category
- JavaScript
- Title
- int to string javascript
- Category
- JavaScript
- Title
- how to send enter event to input field jquery
- Category
- JavaScript
- Title
- how to update react context inside functional component
- Category
- JavaScript
- Title
- how to get the next item in map() js
- Category
- JavaScript
- Title
- cascading dropdown for forms react
- Category
- JavaScript
- Title
- beautify json python
- Category
- JavaScript
- Title
- array of images javascript
- Category
- JavaScript
- Title
- axios delete request payload
- Category
- JavaScript
- Title
- checkbox click event jquery
- Category
- JavaScript
- Title
- find method javascript
- Category
- JavaScript
- Title
- angular material table
- Category
- JavaScript
- Title
- click on a radio button using jquery
- Category
- JavaScript
- Title
- como utilizar jquery
- Category
- JavaScript
- Title
- javascript change url
- Category
- JavaScript
- Title
- how to capitalize a letter based on an index in javascript
- Category
- JavaScript
- Title
- how to iterate array in javascript
- Category
- JavaScript
- Title
- array definition js
- Category
- JavaScript
- Title
- javascript Clone an array
- Category
- JavaScript
- Title
- chart.js on hover and onclick event
- Category
- JavaScript
- Title
- how to have a function inside useeffect
- Category
- JavaScript
- Title
- javascript click event notifications
- Category
- JavaScript
- Title
- how to make a vowel counter in javascript
- Category
- JavaScript
- Title
- if else practice javascript
- Category
- JavaScript
- Title
- adonisjs livereload
- Category
- JavaScript
- Title
- javascript checkbox value
- Category
- JavaScript
- Title
- how to change a string to number in javascript
- Category
- JavaScript
- Title
- angular event scroll end of page
- Category
- JavaScript
- Title
- hello
- Category
- JavaScript
- Title
- initialize array javascript
- Category
- JavaScript
- Title
- javascript clearinterval
- Category
- JavaScript
- Title
- how to avoid inheritance in angular
- Category
- JavaScript