SlideShare a Scribd company logo
1 of 23
ASP.NET 
Validating user input 
Validating user input on the 
client and/or server side 
By-Guddu Kumar
Goals 
Check validity of data from the end user 
How 
Check user input on the client side or on the server 
side 
Examples 
Is the name TextBox empty? 
Does the email TextBox contain a structurally valid 
email address?
 Verifies that a control value is correctly 
entered by the user 
 Blocks the processing of a page until all 
controls are valid 
 Avoids spoofing 
or the addition of 
malicious code
Client-side validation 
 Done in the browser 
 Uses JavaScript 
 Users can disable 
JavaScript! 
 Different browsers → 
different JavaScript 
versions 
 Does not require HTTP 
request + response 
Server-side validation 
 Done on the server 
 Uses C# 
 Requires HTTP request 
+ response
 Best practice 
 Client-side validation and server-side 
validation 
 Client-side saves time 
 No HTTP request/response 
 Server-side 
 Provides security 
 JavaScript not disable
ASP.NET performs browser detection 
• Client supports JavaScript 
• Use client-side validation + server-side validation 
• Client does not support JavaScript 
• Use server-side validation
 RequiredFieldValidator 
Input field cannot be empty 
 CompareValidator 
Compare between user inputs using =, >, etc. 
 RangeValidator 
Minimum < input < maximum 
 RegularExpressionValidator 
Check the entry matches a pattern defined by the regular expression 
 CustomValidator 
Make your own validator 
 ValidationSummary 
Displays all error messages from validators in one spot
 ControlToValidate 
The control to be validated 
 ErrorMessage 
The message used in the ValidationSummary 
 Text 
The error message used in the validation control 
 CssClass 
Style appearance of the messages
• Validation happens because of an event 
• Example: button click event 
• Can be turned of (for some buttons in a form) 
• <asp:Button ID=“Button1” runat=“server” 
Text=“Submit” CausesValidation=“false” > 
• Client-side validation can be turned off 
• Only server-side validation in effect 
• <asp:RequiredFieldValidator … 
EnableClientScript=“false”>
 The RequiredFieldValidator control ensures that the required field is not 
empty. It is generally tied to a text box to force input into the text box. 
The syntax for the control: 
<asp:RequiredFieldValidator ID="rfvcandidate" 
runat="server" ControlToValidate="ddlcandidate" 
ErrorMessage="Please choose a candidate" 
InitialValue="Please choose a candidate"> 
</asp:RequiredFieldValidator>
 Can have multiple validation controls on a 
single input control 
 Only the RequiredFieldValidator checks 
empty controls
 The RangeValidator control verifies that the input value falls within a 
predetermined range. 
 It has three specific properties: 
The syntax for the control: 
<asp:RangeValidator ID="rvclass" 
runat="server" 
ControlToValidate="txtclass" 
ErrorMessage="Enter your class (6 - 12)" 
MaximumValue="12" 
MinimumValue="6" Type="Integer"> 
</asp:RangeValidator>
 The CompareValidator control compares a value in one control with a fixed 
value, or, a value in another control. 
 It has the following specific properties: 
The basic syntax for the control: 
<asp:CompareValidator ID="CompareValidator1" 
runat="server" 
ErrorMessage="CompareValidator"> 
</asp:CompareValidator>
 The RegularExpressionValidator allows validating the input text by matching 
against a pattern against a regular expression. The regular expression is set 
in the ValidationExpression property. 
 The following table summarizes the commonly used syntax constructs for 
regular expressions: 
A class of characters could be specified that can be matched, called the 
metacharacters.
Quantifiers could be added to specify number of times a character could 
appear.
 The CustomValidator control allows writing application specific custom 
validation routines for both the client side and the server side validation. 
 The server side validation routine should be written in any .Net language, 
like C# or VB.Net. 
The basic syntax for the control: 
<asp:CustomValidator ID="CustomValidator1" runat="server" 
ClientValidationFunction=.cvf_func. 
ErrorMessage="CustomValidator"></asp:CustomValidator>
 The ValidationSummary control does not perform any validation but shows a 
summary of all errors in the page. The summary displays the values of the 
ErrorMessage property of all validation controls that failed validation. 
 Using Page.IsValid property we can check for page errors. When there are no 
errors IsValid returns true and user can proceed to next page. 
if (Page.IsValid) 
{ //validation complete proceed } 
The syntax for the control: 
<asp:ValidationSummary ID="ValidationSummary1" runat="server" 
DisplayMode = "BulletList" ShowSummary = "true" 
HeaderText="Errors:" />
 Create an ASP.NET Web Form 
with TextBox and Button 
controls 
 Add a RequiredFieldValidator 
control 
 Add a RangeValidator control 
 Add a 
RegularExpressionValidator 
control
The Following showing the Illustration of Validation controls:
Thank You

More Related Content

What's hot (20)

ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Javascript
JavascriptJavascript
Javascript
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 
Notification android
Notification androidNotification android
Notification android
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Ch 3 event driven programming
Ch 3 event driven programmingCh 3 event driven programming
Ch 3 event driven programming
 
Master page in Asp.net
Master page in Asp.netMaster page in Asp.net
Master page in Asp.net
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
CSS
CSSCSS
CSS
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Scripting Languages
Scripting LanguagesScripting Languages
Scripting Languages
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Java script
Java scriptJava script
Java script
 

Similar to Asp.NET Validation controls

Similar to Asp.NET Validation controls (20)

vnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptx
vnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptxvnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptx
vnd.openxmlformats-officedocument.presentationml.presentation&rendition=1.pptx
 
Validation in asp.net
Validation in asp.netValidation in asp.net
Validation in asp.net
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 
ASP.NET Session 10
ASP.NET Session 10ASP.NET Session 10
ASP.NET Session 10
 
Validation controls ppt
Validation controls pptValidation controls ppt
Validation controls ppt
 
validation-controls.pdf ioue8n uoh souu o3i
validation-controls.pdf ioue8n uoh souu  o3ivalidation-controls.pdf ioue8n uoh souu  o3i
validation-controls.pdf ioue8n uoh souu o3i
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Asp.net validation
Asp.net validationAsp.net validation
Asp.net validation
 
Validation controls ASP .NET
Validation controls ASP .NETValidation controls ASP .NET
Validation controls ASP .NET
 
validation
validationvalidation
validation
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Chapter 3 (validation control)
Chapter 3 (validation control)Chapter 3 (validation control)
Chapter 3 (validation control)
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
validation of aap.net
validation of aap.netvalidation of aap.net
validation of aap.net
 
Introduction to validation
Introduction to validationIntroduction to validation
Introduction to validation
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Visual studio 2008 asp net
Visual studio 2008 asp netVisual studio 2008 asp net
Visual studio 2008 asp net
 
Wheels
WheelsWheels
Wheels
 
Mastering Assertions in Automation Testing, Importance and Best Practices.pdf
Mastering Assertions in Automation Testing, Importance and Best Practices.pdfMastering Assertions in Automation Testing, Importance and Best Practices.pdf
Mastering Assertions in Automation Testing, Importance and Best Practices.pdf
 
validations in asp .net
validations in asp .netvalidations in asp .net
validations in asp .net
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 

Asp.NET Validation controls

  • 1. ASP.NET Validating user input Validating user input on the client and/or server side By-Guddu Kumar
  • 2. Goals Check validity of data from the end user How Check user input on the client side or on the server side Examples Is the name TextBox empty? Does the email TextBox contain a structurally valid email address?
  • 3.  Verifies that a control value is correctly entered by the user  Blocks the processing of a page until all controls are valid  Avoids spoofing or the addition of malicious code
  • 4. Client-side validation  Done in the browser  Uses JavaScript  Users can disable JavaScript!  Different browsers → different JavaScript versions  Does not require HTTP request + response Server-side validation  Done on the server  Uses C#  Requires HTTP request + response
  • 5.  Best practice  Client-side validation and server-side validation  Client-side saves time  No HTTP request/response  Server-side  Provides security  JavaScript not disable
  • 6. ASP.NET performs browser detection • Client supports JavaScript • Use client-side validation + server-side validation • Client does not support JavaScript • Use server-side validation
  • 7.  RequiredFieldValidator Input field cannot be empty  CompareValidator Compare between user inputs using =, >, etc.  RangeValidator Minimum < input < maximum  RegularExpressionValidator Check the entry matches a pattern defined by the regular expression  CustomValidator Make your own validator  ValidationSummary Displays all error messages from validators in one spot
  • 8.  ControlToValidate The control to be validated  ErrorMessage The message used in the ValidationSummary  Text The error message used in the validation control  CssClass Style appearance of the messages
  • 9. • Validation happens because of an event • Example: button click event • Can be turned of (for some buttons in a form) • <asp:Button ID=“Button1” runat=“server” Text=“Submit” CausesValidation=“false” > • Client-side validation can be turned off • Only server-side validation in effect • <asp:RequiredFieldValidator … EnableClientScript=“false”>
  • 10.
  • 11.  The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box. The syntax for the control: <asp:RequiredFieldValidator ID="rfvcandidate" runat="server" ControlToValidate="ddlcandidate" ErrorMessage="Please choose a candidate" InitialValue="Please choose a candidate"> </asp:RequiredFieldValidator>
  • 12.  Can have multiple validation controls on a single input control  Only the RequiredFieldValidator checks empty controls
  • 13.  The RangeValidator control verifies that the input value falls within a predetermined range.  It has three specific properties: The syntax for the control: <asp:RangeValidator ID="rvclass" runat="server" ControlToValidate="txtclass" ErrorMessage="Enter your class (6 - 12)" MaximumValue="12" MinimumValue="6" Type="Integer"> </asp:RangeValidator>
  • 14.  The CompareValidator control compares a value in one control with a fixed value, or, a value in another control.  It has the following specific properties: The basic syntax for the control: <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator"> </asp:CompareValidator>
  • 15.  The RegularExpressionValidator allows validating the input text by matching against a pattern against a regular expression. The regular expression is set in the ValidationExpression property.  The following table summarizes the commonly used syntax constructs for regular expressions: A class of characters could be specified that can be matched, called the metacharacters.
  • 16. Quantifiers could be added to specify number of times a character could appear.
  • 17.  The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation.  The server side validation routine should be written in any .Net language, like C# or VB.Net. The basic syntax for the control: <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction=.cvf_func. ErrorMessage="CustomValidator"></asp:CustomValidator>
  • 18.  The ValidationSummary control does not perform any validation but shows a summary of all errors in the page. The summary displays the values of the ErrorMessage property of all validation controls that failed validation.  Using Page.IsValid property we can check for page errors. When there are no errors IsValid returns true and user can proceed to next page. if (Page.IsValid) { //validation complete proceed } The syntax for the control: <asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode = "BulletList" ShowSummary = "true" HeaderText="Errors:" />
  • 19.  Create an ASP.NET Web Form with TextBox and Button controls  Add a RequiredFieldValidator control  Add a RangeValidator control  Add a RegularExpressionValidator control
  • 20. The Following showing the Illustration of Validation controls:
  • 21.
  • 22.