Contoh
Codingan
php untuk validasi
<!DOCTYPE
html>
<html>
<head>
<title></title>
<script
type="text/javascript">
function validasi(){
var nim
=document.forms["formulir"]["nim"].value;
var nama
=document.forms["formulir"]["nama"].value;
var umur
=document.forms["formulir"]["umur"].value;
var
number=/^[0-9]+$/;
var
huruf=/^[a-zA-Z ]+$/;
var
email=document.forms["formulir"]["email"].value;
var at=
email.indexOf("@");
var dot=
email.lastIndexOf(".");
if(!nim.match(number)){
alert("Nim
Harus Angka ");
return
false;
};
if
(!nama.match(huruf)){
alert("Nama
harus huruf ");
return
false;
};
if (at<1 ||
dot<at+2 || dot+2>=email.length) {
alert("Email
Belum Benar ");
return
false;
};
if (umur<15
|| umur>46) {
alert("Umur
Tidak Sesusai Ketentuan");
return
false;
};
}
</script>
</head>
<body>
<form
method="post" action="data.php"
id="formulir">
<table>
<tr>
<td>NIM</td>
<td><input
type="text" name="NIM" id="nim"></td>
</tr>
<tr>
<td>Nama</td>
<td><input
type="text" name="Nama"
id="nama"></td>
</tr>
<tr>
<td>Email</td>
<td><input
type="text" name="Email"
id="email"></td>
</tr>
<tr>
<td>Umur</td>
<td><input
type="text" name="Umur"
id="umur"></td>
</tr>
<tr>
<td>Username</td>
<td><input
type="text" name="Username"
id="user"></td>
</tr>
<tr>
<td>Password</td>
<td><input
type="text" name="Password"
id="pass"></td>
</tr>
<tr><td><input
type="submit" value="Kirim" name="kirim"
onclick="validasi()"></td></tr>
</table>
</form>
</body>
</html>
|
Sign up here with your email
ConversionConversion EmoticonEmoticon