I'am trying to allow following pattern for a single html input box with javascript regex
- -int (aka any minus number so long it not followed by a zero and is in the first position)
- 0 (a single zero is allowed)
- int (is allowed)
I use this function the remove anything that doesn't match it
$('.dointcheck').live('keyup',
function () {
$(this).val($(this).val().replace((/^((?!:([1-9-]?[0-9])).)/g), ''));
if ($(this).val().length == 0) {
$(this).val(0);
}
});
which doesn't work. Other examples is:
- /[^-0-9]/g it removes any non valid chars but doesnt check if the minus is the beginning and is followed by a zero. It allows minus everywhere in the string
- (/^((?!:([1-9-]?[0-9])).)/g Don't allow none.
- [^1-9-]?[^0-9]* Allow all...
I think I'am missing something.. Any suggestions would be most appreciated..
.live()has been deprecated with v1.7 and removed in v1.9<input type="number" ... />