|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Junior Member
Iscritto dal: Feb 2007
Messaggi: 7
|
JavaScript & Forms!
Ciao a tutti!! Devo validare un form con JavaScript...ho provato anke a prendere validatori già fatti ma niente da fare...non va!! Quindi me ne sono scritto uno io usando un validatore mail funzionante di un mio amico (programmatore informatico)...ma anche questa volta niente...idee?? Vi posto il codice JS:
Codice:
function valida(form) { var empty = 1; if (form.oggetto.value == ""){ form.oggetto.style.backgroundColor="red"; empty=1;} if (form.messaggio.value == ""){ form.messaggio.style.backgroundColor="red"; empty=1;} if (form.file.value == ""){ form.file.style.backgroundColor="red"; empty=1;} if (email_check(form.mail.value) == false){ form.mail.style.backgroundColor="red"; empty=1;} if (empty == 1) {alert('Si prega di compilare tutti i dati!'); return false;} else return true; } function email_check(emailStr) { var checkTLD=1; var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; var emailPat=/^(.+)@(.+)$/; var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; var validChars="\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); var matchArray=emailStr.match(emailPat); if (matchArray==null) return false; var user=matchArray[1]; var domain=matchArray[2]; for (i=0; i<user.length; i++) { if (user.charCodeAt(i)>127) return false; } for (i=0; i<domain.length; i++) { if (domain.charCodeAt(i)>127) return false; } if (user.match(userPat)==null) return false; IPArray=domain.match(ipDomainPat); if(IPArray!=null) { for (var i=1;i<=4;i++) { if (IPArray[i]>255) return false; } return true; } var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i<len;i++) { if (domArr[i].search(atomPat)==-1) return false; } if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) return false; if (len<2) return false; return true; }
__________________
I LOVE ![]() |
![]() |
![]() |
#2 |
Bannato
Iscritto dal: May 2006
Città: Imola - (BO) - Italia Moto: Husqvarna SM125 ripo. DAP: iRiver H120+RockBox. Status attuale: Ernesto.
Messaggi: 1550
|
uhm
|
![]() |
![]() |
#3 |
Bannato
Iscritto dal: Mar 2004
Città: Galapagos Attenzione:utente flautolente,tienilo a mente
Messaggi: 28978
|
what the fuck?
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Jul 1999
Città: Black Mesa
Messaggi: 72457
|
avendo tu già fatto 2 post in PROGRAMMAZIONE immagino che sia stata solo clamorosa svista..
CLOSED!! >bYeZ<
__________________
REGOLAMENTO & update1/update2 | IO C'ERO | Realme X3 SZ 12/256 - History | GTi is BACK
"Non sorridete.......gli spari sopra.....sono per VOI!" |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:37.