I have a php form for a user record, and I'm validating the input type text with javascript
Is there a function in javascript that makes the first character to be entered in a text box be a letter? for now I have validation to text boxes only letters and only numbers, also that the first letter to be entered is capitalized so the user places it in mini, but I would like to validate a text box that when you are going to write, it is mandatory at the beginning start with a letter and then if they can be numbers and so on. Can you?
for the validation of numbers and letters I did the following:
function soloLetras(e) {
key = e.keyCode || e.which;
tecla = String.fromCharCode(key).toString();
letras = " áéíóúabcdefghijklmnñopqrstuvwxyzÁÉÍÓÚABCDEFGHIJKLMNÑOPQRSTUVWXYZ";//Se define todo el abecedario que se quiere que se muestre.
especiales = [8, 9, 37, 39, 46, 6]; //Es la validación del KeyCodes, que teclas recibe el campo de texto.
tecla_especial = false
for(var i in especiales) {
if(key == especiales[i]) {
tecla_especial = true;
break;
}
}
if(letras.indexOf(tecla) == -1 && !tecla_especial){
alert('Este campo solo permite letras');
return false;
}
}
function SoloNumeros(evt){
if(window.event){//asignamos el valor de la tecla a keynum
keynum = evt.keyCode; //IE
}
else{
keynum = evt.which; //FF
}
//comprobamos si se encuentra en el rango numérico y que teclas no recibirá.
if((keynum > 47 && keynum < 58) || keynum == 8 || keynum == 13 || keynum == 6 ){
return true;
}
else{
return false;
}
}
and to apply it in the text boxes, always add the following to the end of the required:
SI ES LETRAS ---> required onkeypress="return soloLetras(event);" onkeyup="this.value = this.value.charAt(0).toUpperCase() + this.value.slice(1);" class="mayusculas" maxlength="15"
SI ES NUMEROS---> onKeyPress="return SoloNumeros(event);"
Now as I want to place a field "address", I want the user to enter it is always a letter at the beginning and not a number, so my query.