javascript masking if input matches patter
document.getElementById("phone").addEventListener("keyup", function(){
// restart the match
this.value = this.value.replace(/\s/g, "");
// Assess the amount needed
var v = this.value.match(/(\d)(\d{1,3})?(\d{1,2})?(\d+)?/);
if(v){
// Save the desired value depending on its existence
v = (v[1]?v[1]+(v[2]?" "+v[2]+(v[3]?" "+v[3]+(v[4]?" "+v[4]:""):""):""):"");
// and yea!
this.value = v;
}
});
Also in JavaScript:
- javascript this
- Javascript check if undefined
- pi in js
- destructure array javascript
- ES6: Use class Syntax to Define a Constructor Function
- clone an object javascript
- redux toolkit reducer
- js call function by string name
- javascript cast bool to int
- replacing each space in a string javascript
- jquery select self and siblings
- create react app theme_color
- set cookie using nest js
- axios post with header
- Javascript convert character to ascii
- how to get date time day year in javscript
- javascript events
- how to change the color using js
- js add element to array
- how to get selected row index of table in javascript
- how to change class by is in js by toggle
- close browser tab javascript
- angular for each
- how to empty table after closing modal using jquery