implementation of react-input-mask
according to "Docs"
Usage notes:
Calls onChange prop after updating its internal value. First argument is the original event, the second is the masked value.
The onChange
event got a second argument with the masked value:
export default function App() {
const [input, setInput] = useState();
const [numbDays, setNumbDays] = useState(0);
const numberOfDays = 7;
const maskInput = (e, masked) => {
setInput(masked);
setNumbDays(masked / numberOfDays);
}
return (
<div className="App">
<CurrencyInput name="myInput" onChange={maskInput} value={input} required />
<h1>input / {numberOfDays} = {numbDays}</h1>
</div>
);
}
How do I implement an input mask with prototype?
You could try MaskedInput hosted at Github and see if that does what you need. I needed input masks a while back, so In lack of alternatives I ported digitalBush Masked Input Plugin for jQuery to Prototype.
Easiest way to mask characters in HTML(5) text input
Look up the new HTML5 Input Types. These instruct browsers to perform client-side filtering of data, but the implementation is incomplete across different browsers. The pattern
attribute will do regex-style filtering, but, again, browsers don't fully (or at all) support it.
However, these won't block the input itself, it will simply prevent submitting the form with the invalid data. You'll still need to trap the onkeydown
event to block key input before it displays on the screen.
ShowMaskOnFocus not working for input-mask in angular
Here i use https://github.com/ngneat/input-mask library.
*.html
<input maxlength="5" placeholder="HH:MM" [inputMask]="time" />
*.ts
time = createMask<Date>({
alias:'datetime',
inputFormat: 'HH:MM'
});
Ref: https://stackblitz.com/edit/angular-ivy-sp6w7d?file=src%2Fapp%2Fapp.component.html
Javascript Input Text Masking without Plugin
You need two inputs
Two inputs should get the job done. One input will contain the masked text and the other will be a hidden input that contains the real data.
<input type="text" name="masknumber">
<input type="text" name="number" style="display:none;">
The way I approached the masking is to build a function for both masking and unmasking the content so everything stays uniform.
$("input[name='masknumber']").on("keyup change", function(){
$("input[name='number']").val(destroyMask(this.value));
this.value = createMask($("input[name='number']").val());
})
function createMask(string){
return string.replace(/(\d{2})(\d{3})(\d{2})/,"$1-$2-$3");
}
function destroyMask(string){
return string.replace(/\D/g,'').substring(0,8);
}
Working JSFiddle
Related Topics
Change Select List Option Background Colour on Hover
What's the Proper Value For a Checked Attribute of an HTML Checkbox
How to Force a Line Break in a Long Word in a Div
Html5 Best Practices; Section/Header/Aside/Article Elements
How to Create a Checkbox With a Clickable Label
How to Force Link from Iframe to Be Opened in the Parent Window
How to Use Content-Disposition For Force a File to Download to the Hard Drive
How to "Disable" Zoom on a Mobile Web Page
How to Open Link in a New Tab in Html
Why Does This Inline-Block Element Have Content That Is Not Vertically Aligned
How to Vertically Center a Container in Bootstrap
How to Use the "Required" Attribute With a "Radio" Input Field
Display: Inline-Block Extra Margin
How to Make a HTML Page in A4 Paper Size Page(S)
Adding a Favicon to a Static HTML Page
Override Browser Form-Filling and Input Highlighting With Html/Css