è javascript... cmq sia...
codice:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
// ovviamente i numeri sono consentiti
var digits = "0123456789";
// sono consentiti anche altri simboli e lo spazio
var phoneNumberDelimiters = "()-/. ";
// il carattere + per i numeri internazionali
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// lunghezza minima di un numero di telefono è di 9 caratteri
var minDigitsInIPhoneNumber = 7;
function isInteger(s)
{ var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function stripCharsInBag(s, bag)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not in bag, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}
function trim(s)
{ var i;
var returnString = "";
// Search through string's characters one by one.
// If character is not a whitespace, append to returnString.
for (i = 0; i < s.length; i++)
{
// Check that current character isn't whitespace.
var c = s.charAt(i);
if (c != " ") returnString += c;
}
return returnString;
}
function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf(")")==-1)return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function isEmail(string)
{
if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
{
return 1;
}
else
{
return 0;
}
}
function Controllo() {
if (document.form1.nome.value == "")
{
alert("Riempire correttamente il campo Nome!")
document.form1.nome.focus()
document.form1.nome.select()
return false;
}
else if ( isEmail(document.form1.email.value) == 0 )
{
alert("Inserisci un valore valido nel campo Email")
document.form1.email.focus()
document.form1.email.select()
return false;
}
else if ((document.form1.telefono.value==null)||(document.form1.telefono.value==""))
{
alert("Riempire correttamente il campo Telefono")
document.form1.telefono.focus()
document.form1.telefono.select()
return false;
}
else if (checkInternationalPhone(document.form1.telefono.value)==false)
{
alert("Inserisci un valore valido nel campo Telefono")
document.form1.telefono.focus()
document.form1.telefono.select()
return false;
}
return true;
}
</SCRIPT>
</head>
<body>
<form name="form1" onsubmit="return Controllo()">
Nome</p>
<input type="text" name="nome">
Email</p>
<input type="text" name="email">
Telefono</p>
<input type="text" name="telefono">
<input type="submit" value="Invia">
</form>
</body>
</html>