You are on page 1of 4

Name – Rimjhim Singh

Reg no – 18BCI0150

IWP Midterm

CODE:

index.html

<html>
<head>
<title>18BCI0150_Midterm
</title>
<script>
function validateForm(){
var mail=document.getElementById("email").value;
var dob=document.getElementById("dob").value;
if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-
]+)*$/.test(bmi.email.value)){
}
else{
alert("Invalid Email");
return false;
}
if(/^\d\d[\-]\d\d[\-]\d\d\d\d$/.match(bmi.dob.value)){
}
else{
alert("Invalid Date format");
return false;
}
}
</script>
</head>
<body>
<form action="output.php" method="POST" onsubmit="return validateForm()"name="bmi">
<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="Name"><br>
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="Email ID"><br>
<label for="dob">DOB</label>
<input type="date" id="dob" name="dob" placeholder="DD-MM-YYYY"><br>
<label for="weight">Weight</label>
<input type="text" id="weight" name="weight" placeholder="Weight in kg"><br>
<label for="height">Height</label>
<input type="text" id="height" name="height" placeholder="Height in m"><br>
<input class="btn" type="submit" value="Calculate BMI">
</form>
</body>
</html>

output.php

<?php
$name=$_POST['name'];
echo "Hi ".strtoupper($name)."<br>";
$mail=$_POST['email'];
$username=strstr($mail,'@',true);
echo "Your Username: ".$username." ";
if($name == $username)
{
echo "True";
} else {
echo "False";
}
echo"<br>";
$from = $_POST['dob'];
echo "Age: ";
echo date_diff(date_create($from), date_create('today'))->y;
echo"<br>";
$w=$_POST['weight'];
$h=$_POST['height'];
$bmi=$w/($h*$h);
echo"Height: ".$h."<br>";
echo"Weight: ".$w."<br>";
echo "BMI Value: ".$bmi;
?>

OUTPUT:

You might also like