Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    primi tre caratteri di stringa

    Ho il seguente quesito da porvi:
    ho un INPUT box , voglio che questa accetti solo 2 tipi di valori:
    - un codice di min 8 cifre e max 11
    - una stringa costituita da 3 crt iniziali e subito dopo (senza spazi e caratteri speciali) 6 cifre.

    Come si fa????? :master:

    Un'altra domandina...
    Una volta compilato questo Input box, devo poter riconoscere che tipo di dato ho inserito e in base al tipo assegnare il valore a due oggetti differenti contenuti nello stesso form della stessa pagina.

    Esempio:

    CASO 1
    Codice : 345678980 => document.form.cod.value = 345678980 => stato = valido;

    Codice : tmp678980 => document.form.cod.value = tmp678980 => stato = temp;

    come si fa???? :master:

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Prova questo.

    codice:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function controlla(unValore) {
     ereg1 = /^tmp[0-9]{6}$/;
     ereg2 = /^[0-9]{8,11}$/;
     //
     if (unValore.match(ereg1)) {
      //-------- matches tmp + 6 figures
    	//alert('ok - tmp');
    	return true;
     } else {
      if (unValore.match(ereg2)) {
       //-------- matches from 8 to 11 figures
    	 //alert('ok - 8-11');
    	 return true; 
    	} else {
    	 //-------- doesnot match anything
       //alert('ko');
    	 return false;
      } // if (unValore.match(ereg2))
     } // if (unValore.match(ereg1))
    } // function controlla(unValore)
    
    function controllaForm() {
     unValore = document.mioform.numero.value;
     if (controlla(unValore)) {
      //-------- controllo immissione
      if (unValore.substr(0,3) == 'tmp') {
    	 document.mioform.cod.value = 'temp';
    	} else {
     	 document.mioform.cod.value = 'valido';
    	} // if (unValore.substr(0,3) == 'tmp')
    	alert( document.mioform.cod.value);
    	return true;
     } else {
      alert('Immissione scoretta\nImpossibile continuare');
      return false
     } // if (controlla(unValore)) 
    } // function controllaForm()
    //-->
    </script>
    
    </head>
    <body>
    <form name="mioform" method="post" onsubmit="return controllaForm()">
     Digitare :
     <input type="text" name="numero" size="13" maxlength="11">
    
     <input type="submit" value="Submit">
     <input type="hidden" name="cod"/>
    </form>
    </body>
    </html>

  3. #3
    Originariamente inviato da badaze
    Prova questo.

    codice:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function controlla(unValore) {
     ereg1 = /^tmp[0-9]{6}$/;
     ereg2 = /^[0-9]{8,11}$/;
     //
     if (unValore.match(ereg1)) {
      //-------- matches tmp + 6 figures
    	//alert('ok - tmp');
    	return true;
     } else {
      if (unValore.match(ereg2)) {
       //-------- matches from 8 to 11 figures
    	 //alert('ok - 8-11');
    	 return true; 
    	} else {
    	 //-------- doesnot match anything
       //alert('ko');
    	 return false;
      } // if (unValore.match(ereg2))
     } // if (unValore.match(ereg1))
    } // function controlla(unValore)
    
    function controllaForm() {
     unValore = document.mioform.numero.value;
     if (controlla(unValore)) {
      //-------- controllo immissione
      if (unValore.substr(0,3) == 'tmp') {
    	 document.mioform.cod.value = 'temp';
    	} else {
     	 document.mioform.cod.value = 'valido';
    	} // if (unValore.substr(0,3) == 'tmp')
    	alert( document.mioform.cod.value);
    	return true;
     } else {
      alert('Immissione scoretta\nImpossibile continuare');
      return false
     } // if (controlla(unValore)) 
    } // function controllaForm()
    //-->
    </script>
    
    </head>
    <body>
    <form name="mioform" method="post" onsubmit="return controllaForm()">
     Digitare :
     <input type="text" name="numero" size="13" maxlength="11">
    
     <input type="submit" value="Submit">
     <input type="hidden" name="cod"/>
    </form>
    </body>
    </html>
    Ti ringrazio...lo provo e poi ti faccio sapere!!!!


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.