0% found this document useful (0 votes)
60 views15 pages

Iwp Lab Assignment 3 DDD PDF

The document contains code for a JavaScript program to validate text input containing the words "red" and "pickup truck" near each other followed by a price. It uses a regular expression to check the string and alerts whether it is valid or not. It also contains code for a doctor's appointment form that validates the required fields like name, age, gender, number of visits, department and appointment date using JavaScript functions. Screenshots of the output validating different fields are provided.

Uploaded by

SUNIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views15 pages

Iwp Lab Assignment 3 DDD PDF

The document contains code for a JavaScript program to validate text input containing the words "red" and "pickup truck" near each other followed by a price. It uses a regular expression to check the string and alerts whether it is valid or not. It also contains code for a doctor's appointment form that validates the required fields like name, age, gender, number of visits, department and appointment date using JavaScript functions. Screenshots of the output validating different fields are provided.

Uploaded by

SUNIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

IWP LAB ASSIGNMENT 3

NAME- VIBHUTI SRIVASTAVA REG.NO- 18BCI0111


Question 1) Develop an automated searching program using JavaScript to search text containing the
word “red” and the phrase “pick-up truck” close to each other, followed by a “price”. Specifically, you
should match the words “red” and the phrase “(pickup/pick-up/pick up) truck” separated by at most
two other words in between. The pick-up truck phrase could appear before or after the word red.
After the words red and the phrase pick-up truck, the text should also contain a price as dollar, for
example, $3.56 and $1,000,000 are valid amounts, whereas $5.321 and $-5, 29, 40 are not. [Hint: Use
Regular expression for validation]

Code-

//18BCI0111 Vibhuti Srivastava

<!DOCTYPE html>

<html>

<head>

<script>

function validateForm() {

var x = document.forms["form"]["fname"].value;

var y="";

var n=x.search(/(((red|Red)(\s[a-z]+){0,2}(\s)(pickup|pick-up|pick\sup)(\s)(truck))|((pickup|pick-
up|pick\sup)(\s)(truck)(\s[a-z]+){0,2}(\s)(red|Red)))(\s)(\$)([0-9]{1,3})((\,)[0-9]{3})*((\.)[0-9]{2})?$/);

if (n==-1){

y=y+"Invalid String!!\n";

if (y!="")

alert(y);

return false;

else{

alert("Submitted Successfully!!");
return false;

</script>

</head>

<body style="text-align: center; margin-top: 150px; ">

<div >

<form name="form" style="font-size: large; font-weight: bolder; display: inline-block; border: 1px solid
#ccc; border-radius: 4px; box-sizing: border-box; padding: 20px; background-color: #ccc;"
onsubmit="return validateForm()">

String: <input type="text" placeholder="Enter string" name="fname" ><br><br>

<input type="submit" value="Submit">

</form>

</div>

</body>

</html>

OUTPUT SCREENSHOTS-
MY WINDOW
RED PICKUP TRUCK

Red pickup truck &35.60


Red pickup truck $3560

Red pickup truck $3,560


Red pickup truck $3.562
Question2) Create a Doctor’s Appointment form with Patient name, Age,
Gender, No of Visits, Appointment Date, Department
• CODE-

<!DOCTYPE html>

<head>

<Ttitle>Patient application form</title>

</head>

<body>

<script>

function CHECK()

var name = document.forms["RegForm"]["name"];

var age = document.forms["RegForm"]["age"];

var gender = document.forms["RegForm"]["gender"];

var visit = document.forms["RegForm"]["visit"];

var dept = document.forms["RegForm"]["dept"];

var appoint=document.forms["RegForm"]["appoint"];

if (name.value == "")

window.alert("Please fill up Name.");

name.focus();

return false;

if (age.value == "")

window.alert("Please fill age.");

age.focus();
return false;

age.value = parseInt(age.value, 10);

if (isNaN(age.value) || age.value < 1 || age.value > 100)

alert("The age must be a number greater than 0");

return false;

if (gender.value =="" )

window.alert("Please fill gender");

gender.focus();

return false;

if (gender.value =='M' || gender.value=='F' ){

else{

alert("Please enter gender in form of M or F.");

return false;

if (visit.value == "")

window.alert("Please fill Number of Visits.");

visit.focus();

return false;

}
visit.value = parseInt(visit.value, 10);

if (isNaN(visit.value) || visit.value < 0)

alert("Please enter the number of visits in positive number");

return false;

if (dept.value == "")

window.alert("Please enter correct Department .");

dept.focus();

return false;

if (dept.value =="Paediatrician" || dept.value=="Ophthalmology" || dept.value=="Cardiac" ||


dept.value=="Dental"){

else{

alert("Department not specified as Paediatrician, Ophthalmology, Cardiac, and Dental.");

return false;

if (appoint.value=="")

alert("Please enter a valid Date.");

appoint.focus();
return false;

dateRe= /^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/;

var Date_1="01/05/2020";

var Date_2="31/05/2020";

D_1 = Date_1.split("/");

D_2 = Date_2.split("/");

D_3 = appoint.value.split("/");

var d1 = new Date(D_1[2], parseInt(D_1[1]) - 1, D_1[0]);

var d2 = new Date(D_2[2], parseInt(D_2[1]) - 1, D_2[0]);

var d3 = new Date(D_3[2], parseInt(D_3[1]) - 1, D_3[0]);

if(appoint.value.match(dateRe) && !(d3 > d1 && d3 < d2 )){

else{

alert("Invalid date format or doctor on vacation. ");

return false;

</script>

<style>

h1{

font-family: 'Times New Roman', Times, serif;

text-align: center;

color: black;
}

form{

color:black;

font-size:large;

font-weight: bold;

font-family: Arial, Helvetica, sans-serif;

text-align: center;

.container {

width: 100%

border-radius: 5px;

background-color: #f2f2f2;

padding: 20px;

align: center;

input[type=text], select {

width: 25%;

padding: 12px 20px;

margin: 8px 0;

display: inline-block;

border: 1px solid #ccc;

border-radius: 4px;

box-sizing: border-box;

}
input[type=submit] {

width: 20%;

background-color: #4CAF50;

color: white;

padding: 14px 20px;

margin: 8px 0;

border: none;

border-radius: 4px;

cursor: pointer;

input[type=submit]:hover {

background-color: #45a049;

div {

border-radius: 5px;

background-color: #f2f2f2;

padding: 20px;

</style>

<div class="container">

<h1>Patient Form</h1>

<form name="RegForm" onsubmit="return CHECK()" method="POST">

<label for="name">Name :</label><br><br>

<input type="text" id="name" name="name"><br><br>


<label for="age">Age:</label><br><br>

<input type="text" id="age" name="age"><br><br>

<label for="gender">Gender:</label><br><br>

<input type="text" placeholder="M/F" id="gender" name="gender"><br><br>

<label for="visit">Number Of Visit:</label><br><br>

<input type="text" id="visit" name="visit"><br><br>

<label for="dept">Department:</label><br><br>

<input type="text" id="dept" name="dept"><br><br>

<label for="appoint">Appointment Date:</label><br><br>

<input type="text" placeholder="DD/MM/YYYY" id="appoint" name="appoint"><br><br>

<input type="submit" value="Submit">

</form>

</div>

</body>

</html>

OUTPUT SCREENSHOTS-
MY FORM
AGE VALIDATION ALERT-

VISIT VALIDATION ALERT-:


DEPARTMENT VALIDATION ALERT-:

DATE VALIDATION ALERT-:

You might also like