Return to Snippet

Revision: 56437
at March 28, 2012 05:04 by serialk89


Initial Code
/**
*
* @permite ingresar sólo letras 
* @versión:1.0.0  @modificado:xx de xx de xxxx   
* @autor: Jaime Quiñones
*
*/
function stringCheck(e, field) {

    key = e.keyCode ? e.keyCode : e.which

	//alert(key);
	//backspace
    if(key == 32) return true;
	
	//numeros 0-9
	if((key >= 48 && key <= 57) || key == 42) return false;

	// Caracteres Raros
	if(	key == 94 || 
		key == 59 || 
		key == 58 || 
		key == 61 || 
		key == 43 || 
		key == 45 || 
		key == 95 || 
		key == 47 || 
		key == 96 || 
		key == 40 || 
		key == 41 || 
		key == 91 || 
		key == 123 || 
		key == 92 || 
		key == 124 || 
		key == 125 || 
		key == 93 || 
		key == 39 || 
		key == 34 || 
		key == 44 || 
		key == 46 || 
		key == 47 || 
		key == 231 || 
		key == 42 || 
		key == 168 || 
		key == 33 || 
		key == 161 || 
		key == 183 || 
		key == 8364 || 
		key == 37 || 
		key == 191 || 
		key == 186 || 
		key == 170 || 
		key == 64 || 
		key == 35 || 
		key == 126 || 
		key == 36 || 
		key == 38 || 
		key == 180 || 
		key == 63) return false;
	
} 


<!-- EN UN INPUT -->
onkeypress="return stringCheck(event, this);"

Initial URL

                                

Initial Description
Valida por medio del metodo onkeypress de un campo input, que solo se ingresen string /[a-zA-Z]/

Initial Title
Validar solo el ingreso de String con Javascript

Initial Tags
javascript, validation

Initial Language
JavaScript