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)

Php forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligetiPhp forms and validations by naveen kumar veligeti
Php forms and validations by naveen kumar veligeti
 
Javascript
JavascriptJavascript
Javascript
 
Css
CssCss
Css
 
Javascript
JavascriptJavascript
Javascript
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
Php forms
Php formsPhp forms
Php forms
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
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
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
CSS Comprehensive Overview
CSS Comprehensive OverviewCSS Comprehensive Overview
CSS Comprehensive Overview
 
What is Ajax technology?
What is Ajax technology?What is Ajax technology?
What is Ajax technology?
 
jQuery
jQueryjQuery
jQuery
 

Viewers also liked (9)

Form Validation
Form ValidationForm Validation
Form Validation
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
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

Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raj Gupta
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
Avanitrambadiya
 
Coding task new
Coding task newCoding task new
Coding task new
Max Friel
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
ch samaram
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
lotlot
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
tutorialsruby
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
tutorialsruby
 

Similar to Form validation client side (20)

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.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
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 

More from Mudasir 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

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

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