SlideShare uma empresa Scribd logo
1 de 33
FORM VALIDATION
Server Side
TOPICS TO BE COVERED
– INTRODUCING SERVER SIDE VALIDATION
– CHECKING EMPTY FIELDS
– CHECKING FIELD LENGTHS
– CHECKING RANGES
– CHECKING FORMATS with Regular Expressions
muhammadabaloch
INTRODUCING SERVER SIDE VALIDATION
muhammadabaloch
INTRODUCING SERVER SIDE VALIDATION
–The act of validating: finding or testing the truth of something.
–The act of declaring or making legally valid
–Validation is the process of checking if something satisfies a certain
standard/ criteria.
muhammadabaloch
INTRODUCING SERVER SIDE VALIDATION
– Form validation is the process of checking that a form has been filled
in correctly before it is processed.
– For example, if your form has a box for the user to type their email
address, you might want your form handler to check that they've
filled in their address before you deal with the rest of the form
– There are two main methods for validating forms: server-side (using
Common Gateway Interface (CGI) scripts, ASP, etc ), and client-
side (usually done using JavaScript). Server-side validation is more
secure but often more tricky to code, whereas client-side (JavaScript)
validation is easier to do and quicker too (the browser doesn't have to
connect to the server to validate the form, so the user finds out
instantly if they've missed out that required field!).
muhammadabaloch
INTRODUCING SERVER SIDE VALIDATION
– Server-side data validation means using PHP to verify that valid
information has been sent to the script. Using server-side validation
has pretty much the exact opposite process and cons of client-side
development: it is more secure and works seamlessly
– with all browsers, but it does so at the cost of slightly higher server
load and slower
– feedback for users.
muhammadabaloch
CHECKING EMPTY FIELDS
– Users are irritating.
– They don't like filling out forms, and will tear through them as fast as
they possibly can to get to the fun part of your site.
– Since they are typing so fast, they probably won't read the directions
and sometimes they leave the fields blank and submit the forms.
– To avoid inserting blank fields in the data base, we bind them to fill
all the required fields
muhammadabaloch
CHECKING EMPTY FIELDS
<?php
$var = "";
if( empty($var ) )
{
echo "The variable is empty";
}
else
{
echo "The variable is having some value";
}
?>
muhammadabaloch
ASSIGNMENT
Enter Last Name
Enter Name
Please fill the field
Enter CNIC number
without using (-) signs
muhammadabaloch
OUTPUT
muhammadabaloch
REGULAR EXPRESSION
What are They…?
muhammadabaloch
REGULAR EXPRESSION
– A regular expression is a specific pattern that provides concise and
flexible means to "match" (specify and recognize) strings of text, such
as particular characters, words, or patterns of characters.
– Common abbreviations for "regular expression" include regex and
regexp.
– They used to only be familiar to Unix users
– A regular expression provides a grammar for a formal language
muhammadabaloch
REGULAR EXPRESSION
– There are 2 types of regular expressions:
1) POSIX (Portable Operating System Interface for Unix)
2) PCRE (Perl Compatible Regular Expression)
– The ereg , eregi , ... are the POSIX versions.
– The preg_match, preg_replace, ... are the Perl version.
– It is important that using Perl compatible regular expressions the expression
should be enclosed in the delimiters, a forward slash (/). However this
version is more powerful and faster as well than the POSIX one.
muhammadabaloch
REGULAR EXPRESSION PCRE (Perl Compatible Regular Expression)
– We will be using PCRE.
– When using the PCRE functions, it is required that the pattern is
enclosed by delimiters.
– A delimiter can be any non-alphanumeric, non-backslash, non-
whitespace character.
– Often used delimiters are forward slashes (/), hash/number signs (#)
and tildes (~).
– The pattern should be written inside double quotation(“ ”)
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
PATTERN SWITCHES
– 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"
muhammadabaloch
PHP FUNCTION Preg_match()
– This function matches the value given by the user and defined in the
regular expression.
– If the regular expression and the value given by the user, becomes
equal, the function will return true, false otherwise.
Syntax:
Preg_match( $Pattern , $Subject , $regs )
– Pattern – Pattern is used to search the string.
– Subject – input given by the user.
– Regs
•If matches are found for parenthesized substrings of pattern and
the function is called with the third argument regs, the matches will
be stored in the elements of the array regs.
PHP FUNCTION Preg_match()
Literal Characters match themselves.
– The Carrot / Circumflex Sign ^
• Means string must start with.
preg_match( “ /^hidaya/ ” , “ hidaya trust ” )
– The Dollar $ sign
• Means string must end with.
preg_match( “ /hidaya$/ ” , “ hidaya trust ” )
– The Period . sign
• Means match any charcter.
preg_match( “ /^d.r/ ” , “ dear ” )
muhammadabaloch
PHP FUNCTION Preg_match()
<?php
$date = "2012-2-3";
$regs = "-";
if ( preg_match ( “/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/ ", $date, $regs ) ) {
echo "$regs[3].$regs[2].$regs[1]";
}
else
{
echo "Invalid date format: $date";
}
?>
muhammadabaloch
PHP FUNCTION Preg_match()
<?php
$pattern = "/^[A-Za-z ]{1,}$/";
$subject = "Hidaya Trust";
if (preg_match( $pattern , $subject ) )
{
echo "Pattern Matched";
}
else
{
echo "Pattern Mismatched";
}
?>
muhammadabaloch
PHP FUNCTION Preg_match()
<?php
$pattern = "/^[A-Z ]{1,}$/i";
$subject = "hidayatrust";
if (preg_match( $pattern , $subject ) )
{
echo "Pattern Matched";
}
else
{
echo "Pattern Mismatched";
}
?>
– The case of characters will be ignored by the pattern
– It will match only the required pattern
muhammadabaloch
PHP FUNCTION Preg_match()
<?php
$pattern = "/^[A-Z ]{1,}.$/i";
$subject = "hidaya trust.";
if (preg_match( $pattern , $subject ) )
{
echo "Pattern Matched";
}
else
{
echo "Pattern Mismatched";
}
?>
– It will match only the required pattern
– The dot(.) is compulsory in the end of the string
muhammadabaloch
PHP FUNCTION ereg( )
– Searches a string for matches to the regular expression given
in pattern in a case-sensitive way.
Syntax
ereg ( $pattern , $string [, array &$regs ] )
– pattern : Case sensitive regular expression (string).
– String: The input string.
– Regs: If matches are found for parenthesized substrings of pattern and the
function is called with the third argument regs, the matches will be stored in
the elements of the array regs.
muhammadabaloch
PHP FUNCTION ereg( )
<?php
$date = "2012-3-22";
$regs = "-";
if (ereg ( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
}
else
{
echo "Invalid date format: $date";
}
?>
muhammadabaloch
PHP FUNCTION preg_replace()
– This function performs the search and replaces the string.
– It works like str_replace()
Syntax
preg_replace ( $Pattern , $Replacement, String / Array )
– Pattern : It is used to search for. It can be either a string or an array with string.
– Replacement : The string or an array with string to replace. If this parameter is a string
and the pattern parameter is an array, all pattern will be replace by that string. If both
pattern and replacement parameters are arrays, each pattern will be replaced by the
replacement counterpart. If there are fewer elements in the replacement array than in
the pattern array, any extra pattern will be replaced by an empty string.
– String/Array – input given by the user
muhammadabaloch
PHP FUNCTION preg_replace()
<?php
$pattern= "/trust$/";
$replacement = "foundation";
$string = "hidaya trust";
echo preg_replace($pattern , $replacement , $string );
?>
muhammadabaloch
PHP FUNCTION preg_replace()
<?php
$pattern = "/^[a-z ]+$/";
$string = "hidaya trust";
$a = preg_match ( $pattern, $string );
if($a)
{
$replacement = "foundation";;
$patt = "/trust/";
echo preg_replace($patt , $replacement , $string );
}
?>
muhammadabaloch
CHECKING FIELD LENGTH
– To restrict the users to fill the forms within the boundary of the
requirements
– To implement server-side validation, we write a PHP script that
handles the validation and then process the data accordingly.
– The user will be bound to enter data within the limit.
– You are very familiar to string functions, they are utilized in the
validation section
muhammadabaloch
CHECKING FIELD LENGTH
$text = "Fah123";
$pattern= "/^[0-9a-zA-Z]{6}$/";
echo preg_match($pattern , $text);
Or
$text= "123456";
$pattern="/^[0-9]{6}$/";
echo preg_match($pattern , $text);
muhammadabaloch
CHECKING FIELD RANGES
– Checking the field ranges is one of the important part of the
validation.
– The user has to insert the data in between the range of the defined
length.
<?php
$text="123456789012";
$pattern="/^[0-9]{6,12}$/";
echo preg_match( $pattern , $text );
?>
muhammadabaloch
ASSIGNMENT
Message should be displayed, if
pattern does not match criteria
muhammadabaloch
INPUT
Message should be displayed, if
pattern does not match criteria
muhammadabaloch
OUTPUT
muhammadabaloch

Mais conteúdo relacionado

Mais procurados

Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfacesAnkur Kumar
 
Artificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
Artificial Neural Networks Lect5: Multi-Layer Perceptron & BackpropagationArtificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
Artificial Neural Networks Lect5: Multi-Layer Perceptron & BackpropagationMohammed Bennamoun
 
Multilayer & Back propagation algorithm
Multilayer & Back propagation algorithmMultilayer & Back propagation algorithm
Multilayer & Back propagation algorithmswapnac12
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showSubhas Malik
 
lazy learners and other classication methods
lazy learners and other classication methodslazy learners and other classication methods
lazy learners and other classication methodsrajshreemuthiah
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
Back face detection
Back face detectionBack face detection
Back face detectionPooja Dixit
 
Removing ambiguity-from-cfg
Removing ambiguity-from-cfgRemoving ambiguity-from-cfg
Removing ambiguity-from-cfgAshik Khan
 
Machine learning with ADA Boost
Machine learning with ADA BoostMachine learning with ADA Boost
Machine learning with ADA BoostAman Patel
 
Regression, Bayesian Learning and Support vector machine
Regression, Bayesian Learning and Support vector machineRegression, Bayesian Learning and Support vector machine
Regression, Bayesian Learning and Support vector machineDr. Radhey Shyam
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production systemHema Kashyap
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 

Mais procurados (20)

C# operators
C# operatorsC# operators
C# operators
 
3 d display-methods
3 d display-methods3 d display-methods
3 d display-methods
 
Hidden lines & surfaces
Hidden lines & surfacesHidden lines & surfaces
Hidden lines & surfaces
 
Artificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
Artificial Neural Networks Lect5: Multi-Layer Perceptron & BackpropagationArtificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
Artificial Neural Networks Lect5: Multi-Layer Perceptron & Backpropagation
 
Multilayer & Back propagation algorithm
Multilayer & Back propagation algorithmMultilayer & Back propagation algorithm
Multilayer & Back propagation algorithm
 
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide showThe complete ASP.NET (IIS) Tutorial with code example in power point slide show
The complete ASP.NET (IIS) Tutorial with code example in power point slide show
 
lazy learners and other classication methods
lazy learners and other classication methodslazy learners and other classication methods
lazy learners and other classication methods
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Back face detection
Back face detectionBack face detection
Back face detection
 
Removing ambiguity-from-cfg
Removing ambiguity-from-cfgRemoving ambiguity-from-cfg
Removing ambiguity-from-cfg
 
Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Machine learning with ADA Boost
Machine learning with ADA BoostMachine learning with ADA Boost
Machine learning with ADA Boost
 
Analysis of the source program
Analysis of the source programAnalysis of the source program
Analysis of the source program
 
Regression, Bayesian Learning and Support vector machine
Regression, Bayesian Learning and Support vector machineRegression, Bayesian Learning and Support vector machine
Regression, Bayesian Learning and Support vector machine
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 

Destaque

Web forms and html lecture Number 4
Web forms and html lecture Number 4Web forms and html lecture Number 4
Web forms and html lecture Number 4Mudasir Syed
 
Form validation client side
Form validation client side Form validation client side
Form validation client side Mudasir Syed
 
Echo Summit 2016 Powerpoint final
Echo Summit 2016 Powerpoint final Echo Summit 2016 Powerpoint final
Echo Summit 2016 Powerpoint final Jennifer Wheeler
 
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
 
Error control, parity check, check sum, vrc
Error control, parity check, check sum, vrcError control, parity check, check sum, vrc
Error control, parity check, check sum, vrcHuawei Technologies
 
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
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011photomatt
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of ItJennifer Jones
 

Destaque (15)

Web forms and html lecture Number 4
Web forms and html lecture Number 4Web forms and html lecture Number 4
Web forms and html lecture Number 4
 
Form validation client side
Form validation client side Form validation client side
Form validation client side
 
Echo Summit 2016 Powerpoint final
Echo Summit 2016 Powerpoint final Echo Summit 2016 Powerpoint final
Echo Summit 2016 Powerpoint final
 
Checking... wave quest
Checking... wave questChecking... wave quest
Checking... wave quest
 
Isup
IsupIsup
Isup
 
Checksum explaination
Checksum explainationChecksum explaination
Checksum explaination
 
Qualification & validation concept & terminology
Qualification & validation concept & terminologyQualification & validation concept & terminology
Qualification & validation concept & terminology
 
Checksum 101
Checksum 101Checksum 101
Checksum 101
 
Qualification & Validation
Qualification & ValidationQualification & Validation
Qualification & Validation
 
Openssl
OpensslOpenssl
Openssl
 
Computer System Validation
Computer System ValidationComputer System Validation
Computer System Validation
 
Error control, parity check, check sum, vrc
Error control, parity check, check sum, vrcError control, parity check, check sum, vrc
Error control, parity check, check sum, vrc
 
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
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 
Guided Reading: Making the Most of It
Guided Reading: Making the Most of ItGuided Reading: Making the Most of It
Guided Reading: Making the Most of It
 

Semelhante a Form validation server side

Beginning Perl
Beginning PerlBeginning Perl
Beginning PerlDave Cross
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007Geoffrey Dunn
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2Dave Cross
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlsana mateen
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionssana mateen
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate PerlDave Cross
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsBrij Kishore
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners PerlDave Cross
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular ExpressionBinsent Ribera
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...Codemotion
 

Semelhante a Form validation server side (20)

Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
Intermediate Perl
Intermediate PerlIntermediate Perl
Intermediate Perl
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular Expression
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 

Mais de 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
 

Mais de 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
 

Último

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
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.pdfAdmir Softic
 
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 pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Último (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
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
 
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 pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Form validation server side

  • 2. TOPICS TO BE COVERED – INTRODUCING SERVER SIDE VALIDATION – CHECKING EMPTY FIELDS – CHECKING FIELD LENGTHS – CHECKING RANGES – CHECKING FORMATS with Regular Expressions muhammadabaloch
  • 3. INTRODUCING SERVER SIDE VALIDATION muhammadabaloch
  • 4. INTRODUCING SERVER SIDE VALIDATION –The act of validating: finding or testing the truth of something. –The act of declaring or making legally valid –Validation is the process of checking if something satisfies a certain standard/ criteria. muhammadabaloch
  • 5. INTRODUCING SERVER SIDE VALIDATION – Form validation is the process of checking that a form has been filled in correctly before it is processed. – For example, if your form has a box for the user to type their email address, you might want your form handler to check that they've filled in their address before you deal with the rest of the form – There are two main methods for validating forms: server-side (using Common Gateway Interface (CGI) scripts, ASP, etc ), and client- side (usually done using JavaScript). Server-side validation is more secure but often more tricky to code, whereas client-side (JavaScript) validation is easier to do and quicker too (the browser doesn't have to connect to the server to validate the form, so the user finds out instantly if they've missed out that required field!). muhammadabaloch
  • 6. INTRODUCING SERVER SIDE VALIDATION – Server-side data validation means using PHP to verify that valid information has been sent to the script. Using server-side validation has pretty much the exact opposite process and cons of client-side development: it is more secure and works seamlessly – with all browsers, but it does so at the cost of slightly higher server load and slower – feedback for users. muhammadabaloch
  • 7. CHECKING EMPTY FIELDS – Users are irritating. – They don't like filling out forms, and will tear through them as fast as they possibly can to get to the fun part of your site. – Since they are typing so fast, they probably won't read the directions and sometimes they leave the fields blank and submit the forms. – To avoid inserting blank fields in the data base, we bind them to fill all the required fields muhammadabaloch
  • 8. CHECKING EMPTY FIELDS <?php $var = ""; if( empty($var ) ) { echo "The variable is empty"; } else { echo "The variable is having some value"; } ?> muhammadabaloch
  • 9. ASSIGNMENT Enter Last Name Enter Name Please fill the field Enter CNIC number without using (-) signs muhammadabaloch
  • 11. REGULAR EXPRESSION What are They…? muhammadabaloch
  • 12. REGULAR EXPRESSION – A regular expression is a specific pattern that provides concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or patterns of characters. – Common abbreviations for "regular expression" include regex and regexp. – They used to only be familiar to Unix users – A regular expression provides a grammar for a formal language muhammadabaloch
  • 13. REGULAR EXPRESSION – There are 2 types of regular expressions: 1) POSIX (Portable Operating System Interface for Unix) 2) PCRE (Perl Compatible Regular Expression) – The ereg , eregi , ... are the POSIX versions. – The preg_match, preg_replace, ... are the Perl version. – It is important that using Perl compatible regular expressions the expression should be enclosed in the delimiters, a forward slash (/). However this version is more powerful and faster as well than the POSIX one. muhammadabaloch
  • 14. REGULAR EXPRESSION PCRE (Perl Compatible Regular Expression) – We will be using PCRE. – When using the PCRE functions, it is required that the pattern is enclosed by delimiters. – A delimiter can be any non-alphanumeric, non-backslash, non- whitespace character. – Often used delimiters are forward slashes (/), hash/number signs (#) and tildes (~). – The pattern should be written inside double quotation(“ ”)
  • 15. 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
  • 16. PATTERN SWITCHES – 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" muhammadabaloch
  • 17. PHP FUNCTION Preg_match() – This function matches the value given by the user and defined in the regular expression. – If the regular expression and the value given by the user, becomes equal, the function will return true, false otherwise. Syntax: Preg_match( $Pattern , $Subject , $regs ) – Pattern – Pattern is used to search the string. – Subject – input given by the user. – Regs •If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of the array regs.
  • 18. PHP FUNCTION Preg_match() Literal Characters match themselves. – The Carrot / Circumflex Sign ^ • Means string must start with. preg_match( “ /^hidaya/ ” , “ hidaya trust ” ) – The Dollar $ sign • Means string must end with. preg_match( “ /hidaya$/ ” , “ hidaya trust ” ) – The Period . sign • Means match any charcter. preg_match( “ /^d.r/ ” , “ dear ” ) muhammadabaloch
  • 19. PHP FUNCTION Preg_match() <?php $date = "2012-2-3"; $regs = "-"; if ( preg_match ( “/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/ ", $date, $regs ) ) { echo "$regs[3].$regs[2].$regs[1]"; } else { echo "Invalid date format: $date"; } ?> muhammadabaloch
  • 20. PHP FUNCTION Preg_match() <?php $pattern = "/^[A-Za-z ]{1,}$/"; $subject = "Hidaya Trust"; if (preg_match( $pattern , $subject ) ) { echo "Pattern Matched"; } else { echo "Pattern Mismatched"; } ?> muhammadabaloch
  • 21. PHP FUNCTION Preg_match() <?php $pattern = "/^[A-Z ]{1,}$/i"; $subject = "hidayatrust"; if (preg_match( $pattern , $subject ) ) { echo "Pattern Matched"; } else { echo "Pattern Mismatched"; } ?> – The case of characters will be ignored by the pattern – It will match only the required pattern muhammadabaloch
  • 22. PHP FUNCTION Preg_match() <?php $pattern = "/^[A-Z ]{1,}.$/i"; $subject = "hidaya trust."; if (preg_match( $pattern , $subject ) ) { echo "Pattern Matched"; } else { echo "Pattern Mismatched"; } ?> – It will match only the required pattern – The dot(.) is compulsory in the end of the string muhammadabaloch
  • 23. PHP FUNCTION ereg( ) – Searches a string for matches to the regular expression given in pattern in a case-sensitive way. Syntax ereg ( $pattern , $string [, array &$regs ] ) – pattern : Case sensitive regular expression (string). – String: The input string. – Regs: If matches are found for parenthesized substrings of pattern and the function is called with the third argument regs, the matches will be stored in the elements of the array regs. muhammadabaloch
  • 24. PHP FUNCTION ereg( ) <?php $date = "2012-3-22"; $regs = "-"; if (ereg ( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) { echo "$regs[3].$regs[2].$regs[1]"; } else { echo "Invalid date format: $date"; } ?> muhammadabaloch
  • 25. PHP FUNCTION preg_replace() – This function performs the search and replaces the string. – It works like str_replace() Syntax preg_replace ( $Pattern , $Replacement, String / Array ) – Pattern : It is used to search for. It can be either a string or an array with string. – Replacement : The string or an array with string to replace. If this parameter is a string and the pattern parameter is an array, all pattern will be replace by that string. If both pattern and replacement parameters are arrays, each pattern will be replaced by the replacement counterpart. If there are fewer elements in the replacement array than in the pattern array, any extra pattern will be replaced by an empty string. – String/Array – input given by the user muhammadabaloch
  • 26. PHP FUNCTION preg_replace() <?php $pattern= "/trust$/"; $replacement = "foundation"; $string = "hidaya trust"; echo preg_replace($pattern , $replacement , $string ); ?> muhammadabaloch
  • 27. PHP FUNCTION preg_replace() <?php $pattern = "/^[a-z ]+$/"; $string = "hidaya trust"; $a = preg_match ( $pattern, $string ); if($a) { $replacement = "foundation";; $patt = "/trust/"; echo preg_replace($patt , $replacement , $string ); } ?> muhammadabaloch
  • 28. CHECKING FIELD LENGTH – To restrict the users to fill the forms within the boundary of the requirements – To implement server-side validation, we write a PHP script that handles the validation and then process the data accordingly. – The user will be bound to enter data within the limit. – You are very familiar to string functions, they are utilized in the validation section muhammadabaloch
  • 29. CHECKING FIELD LENGTH $text = "Fah123"; $pattern= "/^[0-9a-zA-Z]{6}$/"; echo preg_match($pattern , $text); Or $text= "123456"; $pattern="/^[0-9]{6}$/"; echo preg_match($pattern , $text); muhammadabaloch
  • 30. CHECKING FIELD RANGES – Checking the field ranges is one of the important part of the validation. – The user has to insert the data in between the range of the defined length. <?php $text="123456789012"; $pattern="/^[0-9]{6,12}$/"; echo preg_match( $pattern , $text ); ?> muhammadabaloch
  • 31. ASSIGNMENT Message should be displayed, if pattern does not match criteria muhammadabaloch
  • 32. INPUT Message should be displayed, if pattern does not match criteria muhammadabaloch