0% found this document useful (0 votes)
52 views

DIT-OI4-0356/2007 Cat - One Web - Dev (Ii) Discuss Four Validations Citing The Four Different Types of Form Validation (Using Code Examples)

The document discusses four types of form validation - email validation, value validation, digit validation, and empty validation. For each type of validation, the document provides the validation code and describes what each validation checks for, such as checking the syntax of an email for email validation or checking for empty fields for empty validation. The validations can be run on individual fields when changed or all at once when the submit button is clicked.

Uploaded by

williamwachira
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

DIT-OI4-0356/2007 Cat - One Web - Dev (Ii) Discuss Four Validations Citing The Four Different Types of Form Validation (Using Code Examples)

The document discusses four types of form validation - email validation, value validation, digit validation, and empty validation. For each type of validation, the document provides the validation code and describes what each validation checks for, such as checking the syntax of an email for email validation or checking for empty fields for empty validation. The validations can be run on individual fields when changed or all at once when the submit button is clicked.

Uploaded by

williamwachira
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DIT-OI4-0356/2007

CAT – ONE

WEB –DEV (II)

Discuss four validations citing the four different types of form validation (using code examples)

The following are the four types of form validation:

 Email validation
 Value validation
 Digit validation
 Empty validation

You can either validate each field whenever it is changed or you can validate all fields at one time when
the submit button is clicked.

1. Email validation(this,text)
Checking if the content has the general syntax of an email.
Optional parameters are:
text--text that will show in an alertbox if content is illegal.

<html>
<head>
<title><b><u>Email Validation </b></u>
</title>
</head>

<body bgcolor="nevyblue" text="white">


function emailvalidation(entered, alertbox)
{
// E-mail Validation

{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

</body>
</html>
2.Value validation(this,min,max,text,type)
Checking if the content is a number in a limited area.
Optional parameters are:
min --minimum value allowed in the field.
max --maximum value allowed in the field.
text --text that will show in an alertbox if content is illegal.
type --enter "I" if only integers are allowed.

html>
<head>
<title><b><u>Value validation</b></u>
</title>
</head>

<body bgcolor="pink" text="black">

function valuevalidation(entered, min, max, alertbox, datatype)


{
// Value Validation
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) ||
value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
</body>
</html>

3.Digit validation (this,min,max,text,type)


Checking if the content has a certain number of digits.
Optional parameters are:
min --minimum number of digits allowed in the field.
max --maximum number of digits allowed in the field.
text --text that will show in an alertbox if content is illegal.
type --enter "I" if only integers are allowed.

html>
<head>
<title><b><u>Bedtra Tours and Safaris intranet</b></u>
</title>
</head>

<body bgcolor="nevyblue" text="white">

function digitvalidation(entered, min, max, alertbox, datatype)


{
// Digit Validation {
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i")
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) ||
value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
</body>
</html>

4.Empty validation(this,text)
Checking if the field is empty.
Optional parameters are:
text --text that will show in an alertbox if content is illegal.

html>
<head>
<title><b><u>Bedtra Tours and Safaris intranet</b></u>
</title>
</head>

<body bgcolor="nevyblue" text="white">

function emptyvalidation(entered, alertbox)


{
// Emptyfield Validation
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}
</body>
</html>

You might also like