I have an input box:
<input class="longboxsmall" type="text" name="number" value=""/>
And I want to disallow the number 0 being the first number entered in the box how can I do this??? Can I use Jquery??
I have an input box:
<input class="longboxsmall" type="text" name="number" value=""/>
And I want to disallow the number 0 being the first number entered in the box how can I do this??? Can I use Jquery??
JS
$(".longboxsmall").keyup(function(){
var value = $(this).val();
value = value.replace(/^(0*)/,"");
$(this).val(value);
});
HTML
<input class="longboxsmall" type="text" name="number" value=""/>
Try in jsfiddle.
IT's good to intercept another events, like blur, change, focusout, etc. See jquery. Tks @Simen Echholt.
Explanation:
$(".longboxsmall").keyup
Jquery take every element with class longboxsmall
and are ready to call a function on onkeyup event.
var value = $(this).val();
value = value.replace(/^(0*)/,"");
$(this).val(value);
This function uses a regex to replace every 0
in begin (^
) of value.
Of course. Use one of input filter plugins (like this) with suitable regexp.