EX NO : 5 FORM VALIDATION USING JAVASCRIPT DATE: AIM: To validate form and login page using JavaScript. ALGORITHM: 1. Design the login page. Username and Password are text fields, a Checkbox-Remember me, Submit button, a link to the register page. 2. Design the register page to contain the following. Username, password, date of birth, address, phone number, submit and reset buttons. 3. Using JavaScript perform validations for username, password, dob, phone number in the register page. 4. These entries are mandatory. Username must start with character, password and confirm password must match and must be of 4 characters only. Phone number should be 8 digit. 5. An alert box specifies the correct format for each data appears if the user moves from one field to another. 6. The login page checks for username match. If the remember me checkbox is selected, the password field appears.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 1/11
EX NO : 5 FORM VALIDATION USING JAVASCRIPT
DATE:
AIM:
To validate form and login page using JavaScript.
ALGORITHM:
1. Design the login page. Username and Password are text fields, a Checkbox-Remember
me, Submit button, a link to the register page.
2. Design the register page to contain the following. Username, password, date of birth,
address, phone number, submit and reset buttons.
3. Using JavaScript perform validations for username, password, dob, phone number in
the register page.
4. These entries are mandatory. Username must start with character, password and
confirm password must match and must be of 4 characters only. Phone number should
be 8 digit.
5. An alert box specifies the correct format for each data appears if the user moves from
one field to another.
6. The login page checks for username match. If the remember me checkbox is selected,
the password field appears.
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 2/11
DEFINITION:
JavaScript is a scripting language designed to add interactivity to the HTML page.It is usually
embedded directly to the html pages.
DESCRIPTION:
Description Definition Usage
JavaScript variables Declared using the var
keyword.
A variable declared within a
function has a local scope.
Variable declared without the
var keyword ahs a global
scope.
Assigning values to variables
that have not yet beendeclared also are global.
var x=5;
var car;
x=x+y;
y=z-6;
Arithmetic Operators:
+ addition
-Sub
* Multiplication
/Division
% Modulus
++ Increment
--Decrement
Assignment Operators =
+=
-=
*=
%=
/=
x=y
x+=y
y-=z
y*=z
x%=z
x/=z
Comparison Operators = is equal to
== stricty equal to
> Greater than
< Lesser than
<= Lesser than or equal to
>= Greater than or equal to
!= Not equal to
Given that x=5, x=8 is false
x===5 is false
x===5 is true
Logical Operators To determine the logic
between two variables
&&
X=2 y=5
(X<4&&y>4 )is true
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 3/11
||
!
Conditional Statements If..else
if(condition)
{
Code
}
else
{
Code
}
Switch statements
switch(v)
{case 1: execute code
break;
case2:
execute code
break;
default:
}
Popup Boxes Alert Box:
When an alert box comes,user will have to click OK to
proceed.
Confirm Box:
When a confirm box pops up ,
the user has to click either OK
or Cancel to proceed.
Prompt box:
Used when the user has to
enter value before entering
the page.
alert(hello world);
confirm(You agree??);prompt(pls enter your
name);
Functions A function contains code that
will be executed by an event
or call to the function.
Return statement specifies
value to be returned by the
function.
Function xyz()
{
Code;
return x;
}
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 4/11
Loops for(;;)
do while
while
for ..in
Events onLoad and upLoad events
are triggered when user
enters or leaves thepage.Often used to deal with
cookies.
onSubmit event triggers
when submit button is
clicked.
onMouseOver when mouse
is over an HTML element.
onFocus,onBlur,onchange
are used in combination
mith validation of form
fields.
<form name="login_form"
onsubmit="login_check();">
Inserting Special
Characters
The backslash is used to
insert apostrophes,quotes,
and other spl characters.
Code
\
\
\\
Objects An object has method and
properties.
Properties are values
associated with the object.
Methods are actions that
can be performed onobjects.
var text=hello world
document.write(text.length);
op:11
document.write(toUpperCase(text));
op:HELLO WORLD
Regular Expression It is an object that describes
a pattern of characters.
test() is a function that
searches a string for a
var patt=/pattern/
var patt=new RegExp(e);
document.write(pat.test(cse));
op: true
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 5/11
8/7/2019 ExNo05(lena)
http://slidepdf.com/reader/full/exno05lena 6/11
var y=document.f1.t2.value;
var y1=y.length;
if(y1!=4)
window.alert("enter only 4 characters for password");
var z=document.f1.t3.value;
if (z!==y)
window.alert("password mismatch");
var a = document.f1.t4.value;
if(a.length<8)
window.alert("phone number should be of 8 digits");