I have this in asp project:
Lenght is a decimal which calculated from start an finish time, now I change it to changing finish time according to Lenght input. so now I need to doesn’t allow user to enter any thing out of this format hh:mm
How can I do it?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You need to make a mask for the input,In case you are able to use iMask and moment you could do something like this.
let element = document.getElementById('test')
var momentFormat = 'HH:mm';
var momentMask = IMask(element, {
mask: Date,
pattern: momentFormat,
lazy: false,
min: new Date(1970, 0, 1),
max: new Date(2030, 0, 1),
format: function (date) {
return moment(date).format(momentFormat);
},
parse: function (str) {
return moment(str, momentFormat);
},
blocks: {
HH: {
mask: IMask.MaskedRange,
from: 0,
to: 23
},
mm: {
mask: IMask.MaskedRange,
from: 0,
to: 59
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/imask/6.0.5/imask.min.js"></script>
<input type="text" id="test"/>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
