I have an asp text field: textbox in which I must enter 1 to 2 whole numbers from a keyboard created with button type="button", I have not used asp: button because this keyboard and this textbox are inside a modal of bootstrap, and if I used an asp: button I just rebooted the page and closed the modal. Well the case esque I need to validate the textbox so that it only accepts a certain amount of numbers.
I tried with the validation tools that .net already has but it does not work for me, it does not let me write anything in the textbox with the button, so I removed it and tried it with jquery, but it only limits the space when I write with the keyboard of my pc, and if I write with the keyboard that I did, it does not limit me anything.
I hope I made myself understood. Thanks for reading.
<asp:textbox id="sem" runat="server" autocomplete="off"></asp:textbox>
<button id="b1" type="button">1</button>
<button id="b2" type="button">2</button>
<button id="b3" type="button">3</button>
<button id="b4" type="button">4</button>
<button id="b5" type="button">5</button>
<button id="b6" type="button" ...etc..
//Utilice esta función pero como ya dije, si escribo con el teclado que he
hecho me deja escribir más de 2 números.
function validar(){
sem=$('#head_sem').val();
if (sem.length<2){
return true;
}
else {
alert('Maximo 2 caracteres');
return false;
}