Skip to content

Instantly share code, notes, and snippets.

@fastcodecoq
Last active December 23, 2015 16:49
Show Gist options
  • Select an option

  • Save fastcodecoq/6664388 to your computer and use it in GitHub Desktop.

Select an option

Save fastcodecoq/6664388 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="text" onkeypress="keyPress(event,this)" id="tc"/> <button onclick="guarda()"> Verificar
</button>
<button onclick="showStorer()">Ver datos ingresados</button>
</body>
<script>
var storer;
var input;
function keyPress(e, el){
if(e.keyCode === 13)
guarda();
}
function guarda(){
if( !/[\w]/.test(input.value) ) //esto valida si el campo esta vacio
return false;
//escribe aquí el codigo para verificar la tarjeta
//INVESTIGA SOBRE PATRONES ej. de patron TC VISA /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/
if(/^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/.test(input.value) )
alert("La tarjeta es VISA");
//------------
storer.push(input.value); //esta línea guarda si la tarjeta es valida, en caso de que no lo sea no la ejecutes
}
function showStorer(){
alert(JSON.stringify(storer));
}
window.onload = function(){
storer = new Array();
input = document.querySelector("#tc");
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment