Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    472

    Ancora sui caratteri speciali...

    Ho ripreso l'idea di Lucavizzi

    codice:
    <script type="text/javascript">
    function normalonly(myfield, e){
    	if (window.event){
    		key = window.event.keyCode;
    	}else if (e){
    		key = e.which;
    	}else{
    		return true;
    	}
    	keychar = String.fromCharCode(key);
    	var ammessi=/[a-zA-Z0-9àèìòù]+$/; 	
                  if (ammessi.test(keychar)){
    		return true;
    	}else{
    		return false;
    	}
    }
    </script>
    <input onkeypress="return normalonly(this, event)" />

    Solo che avrei bisogno di saper come modificare la parte in rosso visto che i caratteri che vorrei non avere sono i seguenti: (li separo con uno spazio):
    " ' > < \ /

    Grazie

  2. #2
    Utente di HTML.it L'avatar di carlomarx
    Registrato dal
    Oct 2009
    Messaggi
    1,669
    te la semplifico un po'

    codice:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Esempio</title>
    <script type="text/javascript">
    function normalOnly(oToCheckField, oKeyEvent) {
    	if (!oKeyEvent) { oKeyEvent = window.event || { charCode: 0 }; }
    	return oKeyEvent.charCode === 0 || !(/["\/'><\\]/.test(String.fromCharCode(oKeyEvent.charCode)));
    }
    </script>
    </head>
    
    <body>
    <form name="myForm">
    
    
    <input type="text" name="myInput" onkeypress="return(normalOnly(this, event));" onpaste="return(false);" /></p>
    </form>
    </body>
    </html>


    P.S. Ti ho aggiunto l'evento onpaste, la cui assenza avrebbe permesso di aggirare il controllo&hellip;

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2006
    Messaggi
    472
    Alla grande!!!

    grazie mille

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.