SlideShare a Scribd company logo
1 of 31
FORM VALIDATION
client side validation
INTRODUCING CLIENT SIDE VALIDATION
– Checking Empty Fields ...
– Generating Alerts For Invalid Data …
– Practice And Assignments …
muhammadabaloch
INTRODUCING CLIENT SIDE VALIDATION
– When you create forms, providing form validation is useful to ensure
that your customers enter valid and complete data.
– For example, you may want to ensure that someone inserts a valid e-
mail address into a text box, or perhaps you want to ensure that
someone fills in certain fields.
muhammadabaloch
INTRODUCING CLIENT SIDE VALIDATION
– Client-side validation provides validation within the browser on client
computers through JavaScript. Because the code is stored within the page or
within a linked file,
– it is downloaded into the browser when a user accesses the page and,
therefore, doesn't require a round-trip to the server. For this reason,
– client form validation can be faster than server-side validation. However,
– client-side validation may not work in all instances. A user may have a browser
that doesn't support client-side scripting or may have scripting disabled in the
browser. Knowing the limits of client-side scripting helps you decide whether
to use client-side form validation.
muhammadabaloch
ENABLE JAVASCRIPT
• Google Chrome
– Click the wrench icon on the browser toolbar.
– Select Options
– then click Settings.
– Click the Show Advance Settings tab.
– Click Content settings in the "Privacy" section.
– JavaScript
• Allow all sites to run JavaScript (recommended)
• Do not allow any site to run JavaScript (incase to disable JavaScript)
muhammadabaloch
ENABLE JAVASCRIPT
• Mozilla Firefox 3.6+
– Click the Tools menu.
– Select Options.
– Click the Content tab.
– Select the 'Enable JavaScript' checkbox.
– Click the OK button.
muhammadabaloch
CHECKING EMPTY FIELDS
<head>
<script language=“javascript” type=“text/javascript”>
function chkEmpty()
{
var name= document.myform.txtName;
var LName=document.myform.txtLName;
If(name.value==“”)
{
document.getElementById(“txtNameMsg”).innerHTML=“Please fill the field”;
name.focus();
}
else If(LName.value==“”)
{
document.getElementById(“txtLNameMsg”).innerHTML=“Please fill the field”;
LName.focus();
}
muhammadabaloch
CHECKING EMPTY FIELDS
else
{
document.myform.submit();
}
}
</script>
</head>
<html>
<body>
<form action=“process.php” method=“post” name=“myform”>
<table>
<tr><td><input type=“text” name=“txtName”></td>
<td id=“txtNameMsg”></td></tr>
<tr><td><input type=“text” name=“txtLName”></td>
<td id=“txtLNameMsg”></td></tr>
<tr><td><input type=“button” name=“btn” value=“Submit”></td></tr>
</table>
</form>
</body>
</html>
muhammadabaloch
REGULAR EXPRESSIONS
– Regular expressions are very powerful tools for performing pattern
matches. PERL programmers and UNIX shell programmers have
enjoyed the benefits of regular expressions for years. Once you
master the pattern language, most validation tasks become trivial. You
can perform complex tasks that once required lengthy procedures
with just a few lines of code using regular expressions.
– So how are regular expressions implemented in JavaScript?
– There are two ways:
muhammadabaloch
REGULAR EXPRESSIONS
1) Using literal syntax.
2) When you need to dynamically construct the regular expression, via
the RegExp() constructor.
– The literal syntax looks something like:
– var RegularExpression = /pattern/
– while the RegExp() constructor method looks like
– var RegularExpression = new RegExp("pattern");
– The RegExp() method allows you to dynamically construct the search
pattern as a string, and is useful when the pattern is not known ahead
of time.
muhammadabaloch
REGULAR EXPRESSIONS (syntax)
[abc] a, b, or c
[a-z] Any lowercase letter
[^A-Z] Any character that is not
a uppercase letter
[a-z]+ One or more lowercase
letters
[0-9.-] Any number, dot, or minus
sign
^[a-zA-Z0-9_]{1,}$ Any word of at least one
letter, number or _
[^A-Za-z0-9] Any symbol (not a number
or a letter)
([A-Z]{3}|[0-9]{4}) Matches three letters or four
numbers
muhammadabaloch
REGULAR EXPRESSIONS (Metacharacters)
Metacharacter Description
w Finds word character i.e. (alphabets
and number)
W Finds non-word character i.e. (Special
Characters)
d Finds digit i.e. (Numbers)
D Finds non-digit character i.e.
(alphabets and Special Characters)
muhammadabaloch
REGULAR EXPRESSIONS (Pattern Switches or Modifiers)
– use switches to make the match global or case- insensitive or both:
– Switches are added to the very end of a regular expression.
Property Description Example
i Ignore the case of
character
/The/i matches "the"
and "The" and "tHe"
g Global search for all
occurrences of a
pattern
/ain/g matches both
"ain"s in "No pain no
gain", instead of just
the first.
 gi Global search, ignore
case.
/it/gi matches all "it"s
in "It is our IT
department" 
muhammadabaloch
REGULAR EXPRESSIONS (JavaScript RegExp Object )
• What is RegExp … ?
– A regular expression is an object that describes a pattern of characters.
– When you search in a text, you can use a pattern to describe what you are
searching for.
– A simple pattern can be one single character.
– A more complicated pattern can consist of more characters, and can be used for
parsing, format checking, substitution and more.
– Regular expressions are used to perform powerful pattern-matching and "search-
and-replace" functions on text.
Syntax
var patt= new RegExp( pattern , modifiers );
or more simply:
var patt=/pattern/modifiers;
muhammadabaloch
HOW TO CREATE PATTERNS
var pattern = new RegExp(/^[a-z ]{1,}$/);
or
var pattern = /^[a-z]{1,}$/;
var pattern = new RegExp(pattern);
or
var pattern = new RegExp(“^[a-z]{1,}$”);
or
var pattern = “^[a-z]{1,}$”;
var pattern = new RegExp($pattern);
– It will accept only a to z alphabets or only alpha numeric characters, having
minimum length of 1.
muhammadabaloch
HOW TO CREATE PATTERNS (Continued…..)
var pattern = new RegExp(/^[0-9]{1,}$/);
or
var pattern = /^[0-9]{1,}$/;
var pattern = new RegExp(pattern);
or
var pattern = new RegExp(“^[0-9]{1,}$”);
or
var pattern = “^[0-9]{1,}$”;
var pattern = new RegExp(pattern);
– It will accept only numbers between 0 to 9 or only numeric
characters, having minimum length of 1.
muhammadabaloch
RegExp OBJECT METHOD ( test() )
– The test() method tests for a match in a string.
– This method returns true if it finds a match, otherwise it returns false.
Syntax
RegExpObject.test(string)
Parameter Description
string Required. The string to be searched
muhammadabaloch
RegExp OBJECT METHOD ( test() )
<script type="text/javascript">
var str="Hello world!";
var patt=/Hello/g;
var result=patt.test(str);
document.write("Returned value: " + result);
</script>
<script type="text/javascript">
var pattern =new RegExp(/^[a-z]{1,}$/);
var string = "hello world";
var result = pattern.test(string);
document.write("The result = "+ result);
</script>
muhammadabaloch
RegExp OBJECT METHOD (exec() )
– Executes method
– The exec() method tests for a match in a string.
– This method returns the matched text if it finds a match, otherwise it
returns null.
Syntax
RegExpObject.exec(string)
Parameter Description
string Required. The string to be searched
muhammadabaloch
RegExp OBJECT METHOD (exec() )
<script type="text/javascript">
var str="Hello world!";
var patt=/Hello/g;
var result=patt.exec(str);
document.write("Returned value: " + result);
</script>
<script language="javascript" type="text/javascript">
var str="The rain in SPAIN stays mainly in the plain";
var pattern = new RegExp(/[a-z]{1,}/gi);
var result = pattern.exec(str);
document.write("The result = "+ result);
</script>
muhammadabaloch
STRING OBJECT METHOD (replace())
– The replace() method searches a string for a specified value, or
a regular expression, and returns a new string where the specified
values are replaced.
Syntax
string.replace( searchvalue , newvalue )
Parameter Description
searchvalue Required. The value, or regular
expression, that will be replaced by
the new value
newvalue Required. The value to replace the
searchvalue with
muhammadabaloch
STRING OBJECT METHOD (replace())
<script language="javascript" type="text/javascript">
var str="Mr Blue has a blue house and a blue car";
var n=str.replace(/blue/g,"red");
document.write(n);
</script>
muhammadabaloch
STRING OBJECT METHOD (match())
– The match() method searches a string for a match against a regular
expression, and
returns the matches, as an Array object.
– Note: If the regular expression does not include the g modifier (to perform
a global search),
– the match() method will return only the first match in the string.
– This method returns null if no match is found.
Syntax
string.match(regexp)
– The return type of match() method is array.
Parameter Description
regexp Required. The value to search for, as a
regular expression.
muhammadabaloch
STRING OBJECT METHOD (match())
<script language="javascript" type="text/javascript">
var str="The rain in SPAIN stays mainly in the plain";
var result=str.match(/ain/gi);
document.write("The result = "+ result);
</script>
• The result of n will be:
• ain,AIN,ain,ain
muhammadabaloch
STRING OBJECT METHOD (match())
<script language="javascript" type="text/javascript">
var pattern = new RegExp(/ain/gi);
var result = str.match(pattern);
document.write("The result = "+ result);
</script>
The result of n will be:
ain,AIN,ain,ain
muhammadabaloch
STRING OBJECT METHOD (match())
<script language="javascript" type="text/javascript">
var str ="The rain in SPAIN stays mainly in the plain";
var pattern = new RegExp(/ [a-z]{1,}/gi);
var result = str.match(pattern);
document.write("The result = "+ result);
</script>
– The result of n will be:
– The,rain,in,SPAIN,stays,mainly,in,the,plain
muhammadabaloch
STRING OBJECT METHOD (search())
– The search() method searches a string for a specified value, or regular
expression, and returns the position of the match.
– This method returns -1 if no match is found.
Syntax
string.search(searchvalue)
Parameter Description
searchvalue Required. The value, or regular
expression, to search for.
muhammadabaloch
STRING OBJECT METHOD (search())
– The return type is integer.
var str=“Hidaya Trust!";
var n=str.search(“Trust");
– The result of n will be:
– 7
muhammadabaloch
STRING OBJECT METHOD (search())
<script language="javascript" type="text/javascript">
var str="Mr Blue has a blue house and a blue car";
var result=str.search(/blue/g);
document.write(result);
</script>
muhammadabaloch
ASSIGNMENT
Submit
First Name
Last Name
CNIC #
Enter Last Name
Enter Name
Enter CNIC
number
Invalid Format, Only alpha
numeric characters are alowed
Please fill the
field
muhammadabaloch
OUTPUT
muhammadabaloch

More Related Content

What's hot

What's hot (20)

Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
virtual hosting and configuration
virtual hosting and configurationvirtual hosting and configuration
virtual hosting and configuration
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
Background property in css
Background property in cssBackground property in css
Background property in css
 
SOAP - Simple Object Access Protocol
SOAP - Simple Object Access ProtocolSOAP - Simple Object Access Protocol
SOAP - Simple Object Access Protocol
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
 
Responsive web designing ppt(1)
Responsive web designing ppt(1)Responsive web designing ppt(1)
Responsive web designing ppt(1)
 
Css backgrounds
Css   backgroundsCss   backgrounds
Css backgrounds
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
PHP Regular Expressions
PHP Regular ExpressionsPHP Regular Expressions
PHP Regular Expressions
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Express js
Express jsExpress js
Express js
 

Viewers also liked

Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScriptRavi Bhadauria
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chananakaranchanan
 
Javascript validation assignment
Javascript validation assignmentJavascript validation assignment
Javascript validation assignmentH K
 
Form validation server side
Form validation server side Form validation server side
Form validation server side Mudasir Syed
 
Qualification & validation concept & terminology
Qualification & validation concept & terminologyQualification & validation concept & terminology
Qualification & validation concept & terminologyMuhammad Luqman Ikram
 
Qualification & Validation
Qualification & ValidationQualification & Validation
Qualification & ValidationICHAPPS
 
Computer System Validation
Computer System ValidationComputer System Validation
Computer System ValidationEric Silva
 
Concept of URS,DQ,IQ,OQ,PQ
Concept of URS,DQ,IQ,OQ,PQConcept of URS,DQ,IQ,OQ,PQ
Concept of URS,DQ,IQ,OQ,PQdhavalrock24
 

Viewers also liked (10)

Form Validation
Form ValidationForm Validation
Form Validation
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
 
Javascript validation karan chanana
Javascript validation karan chananaJavascript validation karan chanana
Javascript validation karan chanana
 
Javascript validation assignment
Javascript validation assignmentJavascript validation assignment
Javascript validation assignment
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
 
Qualification & validation concept & terminology
Qualification & validation concept & terminologyQualification & validation concept & terminology
Qualification & validation concept & terminology
 
Qualification & Validation
Qualification & ValidationQualification & Validation
Qualification & Validation
 
Computer System Validation
Computer System ValidationComputer System Validation
Computer System Validation
 
Concept of URS,DQ,IQ,OQ,PQ
Concept of URS,DQ,IQ,OQ,PQConcept of URS,DQ,IQ,OQ,PQ
Concept of URS,DQ,IQ,OQ,PQ
 

Similar to Form validation client side

JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08Terry Yoast
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String FunctionsAvanitrambadiya
 
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...ICS User Group
 
Coding task new
Coding task newCoding task new
Coding task newMax Friel
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptxMattMarino13
 
Regular expression unit2
Regular expression unit2Regular expression unit2
Regular expression unit2smitha273566
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoftch samaram
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuationlotlot
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
 

Similar to Form validation client side (20)

JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
Icsug dev day2014_road to damascus - conversion experience-lotusscript and @f...
 
Coding task new
Coding task newCoding task new
Coding task new
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Java script
Java scriptJava script
Java script
 
Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Regular expression unit2
Regular expression unit2Regular expression unit2
Regular expression unit2
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 

More from Mudasir Syed

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2Mudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1Mudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1 Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminMudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 

More from Mudasir Syed (20)

Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
 
Ajax
Ajax Ajax
Ajax
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Form validation client side

  • 2. INTRODUCING CLIENT SIDE VALIDATION – Checking Empty Fields ... – Generating Alerts For Invalid Data … – Practice And Assignments … muhammadabaloch
  • 3. INTRODUCING CLIENT SIDE VALIDATION – When you create forms, providing form validation is useful to ensure that your customers enter valid and complete data. – For example, you may want to ensure that someone inserts a valid e- mail address into a text box, or perhaps you want to ensure that someone fills in certain fields. muhammadabaloch
  • 4. INTRODUCING CLIENT SIDE VALIDATION – Client-side validation provides validation within the browser on client computers through JavaScript. Because the code is stored within the page or within a linked file, – it is downloaded into the browser when a user accesses the page and, therefore, doesn't require a round-trip to the server. For this reason, – client form validation can be faster than server-side validation. However, – client-side validation may not work in all instances. A user may have a browser that doesn't support client-side scripting or may have scripting disabled in the browser. Knowing the limits of client-side scripting helps you decide whether to use client-side form validation. muhammadabaloch
  • 5. ENABLE JAVASCRIPT • Google Chrome – Click the wrench icon on the browser toolbar. – Select Options – then click Settings. – Click the Show Advance Settings tab. – Click Content settings in the "Privacy" section. – JavaScript • Allow all sites to run JavaScript (recommended) • Do not allow any site to run JavaScript (incase to disable JavaScript) muhammadabaloch
  • 6. ENABLE JAVASCRIPT • Mozilla Firefox 3.6+ – Click the Tools menu. – Select Options. – Click the Content tab. – Select the 'Enable JavaScript' checkbox. – Click the OK button. muhammadabaloch
  • 7. CHECKING EMPTY FIELDS <head> <script language=“javascript” type=“text/javascript”> function chkEmpty() { var name= document.myform.txtName; var LName=document.myform.txtLName; If(name.value==“”) { document.getElementById(“txtNameMsg”).innerHTML=“Please fill the field”; name.focus(); } else If(LName.value==“”) { document.getElementById(“txtLNameMsg”).innerHTML=“Please fill the field”; LName.focus(); } muhammadabaloch
  • 8. CHECKING EMPTY FIELDS else { document.myform.submit(); } } </script> </head> <html> <body> <form action=“process.php” method=“post” name=“myform”> <table> <tr><td><input type=“text” name=“txtName”></td> <td id=“txtNameMsg”></td></tr> <tr><td><input type=“text” name=“txtLName”></td> <td id=“txtLNameMsg”></td></tr> <tr><td><input type=“button” name=“btn” value=“Submit”></td></tr> </table> </form> </body> </html> muhammadabaloch
  • 9. REGULAR EXPRESSIONS – Regular expressions are very powerful tools for performing pattern matches. PERL programmers and UNIX shell programmers have enjoyed the benefits of regular expressions for years. Once you master the pattern language, most validation tasks become trivial. You can perform complex tasks that once required lengthy procedures with just a few lines of code using regular expressions. – So how are regular expressions implemented in JavaScript? – There are two ways: muhammadabaloch
  • 10. REGULAR EXPRESSIONS 1) Using literal syntax. 2) When you need to dynamically construct the regular expression, via the RegExp() constructor. – The literal syntax looks something like: – var RegularExpression = /pattern/ – while the RegExp() constructor method looks like – var RegularExpression = new RegExp("pattern"); – The RegExp() method allows you to dynamically construct the search pattern as a string, and is useful when the pattern is not known ahead of time. muhammadabaloch
  • 11. REGULAR EXPRESSIONS (syntax) [abc] a, b, or c [a-z] Any lowercase letter [^A-Z] Any character that is not a uppercase letter [a-z]+ One or more lowercase letters [0-9.-] Any number, dot, or minus sign ^[a-zA-Z0-9_]{1,}$ Any word of at least one letter, number or _ [^A-Za-z0-9] Any symbol (not a number or a letter) ([A-Z]{3}|[0-9]{4}) Matches three letters or four numbers muhammadabaloch
  • 12. REGULAR EXPRESSIONS (Metacharacters) Metacharacter Description w Finds word character i.e. (alphabets and number) W Finds non-word character i.e. (Special Characters) d Finds digit i.e. (Numbers) D Finds non-digit character i.e. (alphabets and Special Characters) muhammadabaloch
  • 13. REGULAR EXPRESSIONS (Pattern Switches or Modifiers) – use switches to make the match global or case- insensitive or both: – Switches are added to the very end of a regular expression. Property Description Example i Ignore the case of character /The/i matches "the" and "The" and "tHe" g Global search for all occurrences of a pattern /ain/g matches both "ain"s in "No pain no gain", instead of just the first.  gi Global search, ignore case. /it/gi matches all "it"s in "It is our IT department"  muhammadabaloch
  • 14. REGULAR EXPRESSIONS (JavaScript RegExp Object ) • What is RegExp … ? – A regular expression is an object that describes a pattern of characters. – When you search in a text, you can use a pattern to describe what you are searching for. – A simple pattern can be one single character. – A more complicated pattern can consist of more characters, and can be used for parsing, format checking, substitution and more. – Regular expressions are used to perform powerful pattern-matching and "search- and-replace" functions on text. Syntax var patt= new RegExp( pattern , modifiers ); or more simply: var patt=/pattern/modifiers; muhammadabaloch
  • 15. HOW TO CREATE PATTERNS var pattern = new RegExp(/^[a-z ]{1,}$/); or var pattern = /^[a-z]{1,}$/; var pattern = new RegExp(pattern); or var pattern = new RegExp(“^[a-z]{1,}$”); or var pattern = “^[a-z]{1,}$”; var pattern = new RegExp($pattern); – It will accept only a to z alphabets or only alpha numeric characters, having minimum length of 1. muhammadabaloch
  • 16. HOW TO CREATE PATTERNS (Continued…..) var pattern = new RegExp(/^[0-9]{1,}$/); or var pattern = /^[0-9]{1,}$/; var pattern = new RegExp(pattern); or var pattern = new RegExp(“^[0-9]{1,}$”); or var pattern = “^[0-9]{1,}$”; var pattern = new RegExp(pattern); – It will accept only numbers between 0 to 9 or only numeric characters, having minimum length of 1. muhammadabaloch
  • 17. RegExp OBJECT METHOD ( test() ) – The test() method tests for a match in a string. – This method returns true if it finds a match, otherwise it returns false. Syntax RegExpObject.test(string) Parameter Description string Required. The string to be searched muhammadabaloch
  • 18. RegExp OBJECT METHOD ( test() ) <script type="text/javascript"> var str="Hello world!"; var patt=/Hello/g; var result=patt.test(str); document.write("Returned value: " + result); </script> <script type="text/javascript"> var pattern =new RegExp(/^[a-z]{1,}$/); var string = "hello world"; var result = pattern.test(string); document.write("The result = "+ result); </script> muhammadabaloch
  • 19. RegExp OBJECT METHOD (exec() ) – Executes method – The exec() method tests for a match in a string. – This method returns the matched text if it finds a match, otherwise it returns null. Syntax RegExpObject.exec(string) Parameter Description string Required. The string to be searched muhammadabaloch
  • 20. RegExp OBJECT METHOD (exec() ) <script type="text/javascript"> var str="Hello world!"; var patt=/Hello/g; var result=patt.exec(str); document.write("Returned value: " + result); </script> <script language="javascript" type="text/javascript"> var str="The rain in SPAIN stays mainly in the plain"; var pattern = new RegExp(/[a-z]{1,}/gi); var result = pattern.exec(str); document.write("The result = "+ result); </script> muhammadabaloch
  • 21. STRING OBJECT METHOD (replace()) – The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced. Syntax string.replace( searchvalue , newvalue ) Parameter Description searchvalue Required. The value, or regular expression, that will be replaced by the new value newvalue Required. The value to replace the searchvalue with muhammadabaloch
  • 22. STRING OBJECT METHOD (replace()) <script language="javascript" type="text/javascript"> var str="Mr Blue has a blue house and a blue car"; var n=str.replace(/blue/g,"red"); document.write(n); </script> muhammadabaloch
  • 23. STRING OBJECT METHOD (match()) – The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object. – Note: If the regular expression does not include the g modifier (to perform a global search), – the match() method will return only the first match in the string. – This method returns null if no match is found. Syntax string.match(regexp) – The return type of match() method is array. Parameter Description regexp Required. The value to search for, as a regular expression. muhammadabaloch
  • 24. STRING OBJECT METHOD (match()) <script language="javascript" type="text/javascript"> var str="The rain in SPAIN stays mainly in the plain"; var result=str.match(/ain/gi); document.write("The result = "+ result); </script> • The result of n will be: • ain,AIN,ain,ain muhammadabaloch
  • 25. STRING OBJECT METHOD (match()) <script language="javascript" type="text/javascript"> var pattern = new RegExp(/ain/gi); var result = str.match(pattern); document.write("The result = "+ result); </script> The result of n will be: ain,AIN,ain,ain muhammadabaloch
  • 26. STRING OBJECT METHOD (match()) <script language="javascript" type="text/javascript"> var str ="The rain in SPAIN stays mainly in the plain"; var pattern = new RegExp(/ [a-z]{1,}/gi); var result = str.match(pattern); document.write("The result = "+ result); </script> – The result of n will be: – The,rain,in,SPAIN,stays,mainly,in,the,plain muhammadabaloch
  • 27. STRING OBJECT METHOD (search()) – The search() method searches a string for a specified value, or regular expression, and returns the position of the match. – This method returns -1 if no match is found. Syntax string.search(searchvalue) Parameter Description searchvalue Required. The value, or regular expression, to search for. muhammadabaloch
  • 28. STRING OBJECT METHOD (search()) – The return type is integer. var str=“Hidaya Trust!"; var n=str.search(“Trust"); – The result of n will be: – 7 muhammadabaloch
  • 29. STRING OBJECT METHOD (search()) <script language="javascript" type="text/javascript"> var str="Mr Blue has a blue house and a blue car"; var result=str.search(/blue/g); document.write(result); </script> muhammadabaloch
  • 30. ASSIGNMENT Submit First Name Last Name CNIC # Enter Last Name Enter Name Enter CNIC number Invalid Format, Only alpha numeric characters are alowed Please fill the field muhammadabaloch