Help with field validation in javascript?

0

Friends what is happening is that you are passing spaces and repeated numbers, I do not know what else to do: P

<form name="form" id="form" action="passo_01.php" method="post" onSubmit="return validasucesso()">

<td bgcolor="#F7F7F7" ><input name="table1" type="text" id="table1" lang="1" onKeyUp="javascript:pulacampo('table1','table2');" size="3" maxlength="4" onKeyPress="return SomenteNumero(event)" autofocus /></td>
  

function IsNumeric(){
    		myForm = document.getElementById("form");
    		var myArray=[];
    		for(i=0;i<myForm.elements.length;i++){
    			if(myForm.elements[i].type=='number'){
    				myArray[myArray.length]=myForm.elements[i].value;
    			}
    		}
    		myArray.sort();
    		for(i=0;i<myArray.length-1;i++){
    			if(myArray[i]==myArray[i+1]){
    				alert('Chaves repitidas no formulário!');
    				selectkey(myArray[i]);
    				return false;
    				break;
    				exit;
    			}
    		}
    		return true;
}

function validasucesso(){
	var i;
	var value;
	for (i = 1;i <=70;i ++) {
	   eval("value = document.form.table" + i + ".value");
    	if (value.length < 4)	{
			alert("Cartão de segurança inválido, verifique os dígitos corretamente."); 
			eval("document.form.table" + i +".focus()");
			return false;
		}		
		
		if (IsNumeric(value)) {
		}
		else
		{
			alert("Cartão de segurança inválido, verifique os dígitos corretamente."); 
			eval("document.form.table" + i +".focus()");
			return false;
		}
	}
		for (i = 1;i <=70;i ++) {
		   eval("value = document.form.table" + i + ".value");
		   eval("document.form.table" + i + ".value = value");
		}	
}

    
asked by anonymous 28.06.2017 / 04:30

1 answer

0

    $(function(){
      $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace(/\s+/g, '');
        });
      });
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('99', '9');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('88', '8');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('77', '7');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('66', '6');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('55', '5');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('44', '4');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('33', '3');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('22', '2');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('11', '1');
        });
      });      
    $('#smesp').bind('input', function(){
        $(this).val(function(_, v){
         return v.replace('00', '0');
        });
      });      
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><textareaid="smesp"></textarea>
    
28.06.2017 / 04:57