SlideShare a Scribd company logo
1 of 14
• Understanding Validation
• Validation Controls
• BaseValidator Class Properties
• Validator Specific Properties
• Validating with Regular Expressions
• Regular Expression Characters
• Commonly used Regular Expressions
• Validation Summary Control
• Manual Validation
• Validation Groups
Validation means ensuring that the data inserted into an
application satisfies defined formats and other input criteria.


Some possible mistakes a user can make:
• Users might ignore an important field and leave it blank.
• Users might try to type a short string of nonsense to
  circumvent a required field check.
• Enter a nonnumeric character in a number field.
• Malicious users might try to exploit a weakness in your
  code by entering carefully structured wrong values
ASP.NET provides five validator controls. Four are
targeted at specific types of validation, while the fifth
allows you to apply custom validation routines
All the validation controls are found in the System.Web.UI.WebControls
namespace and inherit from the BaseValidator class.

Property             Description
ControlToValidate    Identifies the control that is to be validated
Error Message        If validation fails, the validator control can display a text
                     message set by this property
ForeColor            By changing the ForeColor, you can make the error
                     message stand out
Display              Dynamic, Static or None
IsValid              Returns true or false depending on whether it
                     succeeded or failed
Enabled              When set to false, automatic validation will not be
                     performed for this control when the page is submitted
EnableClientScript   If set to true, ASP.NET will add JavaScript and DHTML
                     code to allow client-side validation on browsers that
                     support it.
One of ASP.NET’s most powerful validation controls is the
RegularExpressionValidator, which validates text by determining
whether it matches a specific pattern.

333sddd
s represents any whitespace character (such as a space or tab). d
represents any digit

You can use the plus (+) sign to represent a repeated character. For
example, 5+7 means “one or more occurrences of the character 5,
followed by a single 7.” The number 57 would match, as would
555557

The following expression would match any word that starts with a
letter from a to f, contains one or more “word” characters (letters),
and ends with ing—possible matches include acting and developing.
[a-f]w+ing
In some modern browsers, ASP.NET automatically
adds JavaScript code for client-side validation. In this
case, when the user clicks a CausesValidation button,
the same error messages will appear without the page
needing to be submitted and returned from the server.
This increases the responsiveness of your web page.

However, even if the page validates successfully on
the client side, ASP.NET still revalidates it when it’s
received at the server.
What happens when the user clicks a button :

• If CausesValidation is false, ASP.NET will ignore the
validation controls, the page will be posted back, and
your event handling code will run normally.

• If CausesValidation is true (the default), ASP.NET will
automatically validate the page when the user clicks
the button. It does this by performing the validation for
each control on the page. If any control fails to
validate, ASP.NET will return the page with some error
information. Your click event handling code may or
may not be executed.
Use IsValid property in a conditional logic and write
event handling code inside it.
Accommodates all the error messages from all the
validation controls at a suitable location normally at the
bottom of the page.

Error messages from all the validators are hided by
setting their Display property to None.

When you run the page, you won’t see any dynamic
messages as you enter invalid information and
tab to a new field. However, when you click the OK
button, the ValidationSummary will appear with a list
of all error messages.

It automatically retrieves the value of the ErrorMessage
property from each validator
In some cases, you’ll want to display a full message in
the summary and some sort of visual indicator next to
the offending control

You can use this technique with the help of the Text
property of the validators. Ordinarily, Text is left empty,
and the validator doesn’t show any content in the web
page. However, if you set both Text and ErrorMessage,
the ErrorMessage value will be used for the summary
while the Text value is displayed in the validator.

Of course, you’ll need to make sure you aren’t also
setting the Display property of your validator to None.
Manual validation is when you disable validation and perform
the work on your own. This allows you to create a specialized
error message of your own.
You can create manual validation in one of three ways:

I.    Use your own code to verify values. In this case, you
      won’t use any of the ASP.NET validation controls.

II.   Disable the EnableClientScript property for each
      validation control. This allows an invalid page to be
      submitted, after which you can decide what to do with
      itdepending on the problems that may exist.

III. Add a button with CausesValidation set to false. When
     this button is clicked, manually validate the page by
     calling the Page.Validate() method. Then examine the
     IsValid property, and decide what to do.
Every control that provides a CausesValidation property
also includes the ValidationGroup property.

In some situations you might have several distinct groups of
controls, possibly in separate panels and you may want to
perform validations separately.

To create a validation group, you need to set the
ValidationGroup property of every control in the same
logical group with the same descriptive string.

More Related Content

What's hot

Less04 2 e_testermodule_3
Less04 2 e_testermodule_3Less04 2 e_testermodule_3
Less04 2 e_testermodule_3
Suresh Mishra
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
mindqqa
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9
Sisir Ghosh
 
Selenium ide1
Selenium ide1Selenium ide1
Selenium ide1
mindqqa
 
Selenium
SeleniumSelenium
Selenium
nil65
 

What's hot (20)

ASP.NET Validation Control
ASP.NET Validation ControlASP.NET Validation Control
ASP.NET Validation Control
 
Data validation in web applications
Data validation in web applicationsData validation in web applications
Data validation in web applications
 
Create rest webservice for oracle public api using java class via jdeveloper
Create rest webservice for oracle public api using java class via jdeveloperCreate rest webservice for oracle public api using java class via jdeveloper
Create rest webservice for oracle public api using java class via jdeveloper
 
Less04 2 e_testermodule_3
Less04 2 e_testermodule_3Less04 2 e_testermodule_3
Less04 2 e_testermodule_3
 
Build Restful Service using ADFBC
Build Restful Service using ADFBCBuild Restful Service using ADFBC
Build Restful Service using ADFBC
 
Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2Request Validation In Spring Rest-Part2
Request Validation In Spring Rest-Part2
 
How to build quality software
How to build quality softwareHow to build quality software
How to build quality software
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Spring REST Request Validation
Spring REST Request ValidationSpring REST Request Validation
Spring REST Request Validation
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9
 
Automating with selenium2
Automating with selenium2Automating with selenium2
Automating with selenium2
 
Using galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingUsing galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testing
 
Practical Dynamic Actions - Intro
Practical Dynamic Actions - IntroPractical Dynamic Actions - Intro
Practical Dynamic Actions - Intro
 
Selenium ide1
Selenium ide1Selenium ide1
Selenium ide1
 
Transforming Power Point Show with VBA
Transforming Power Point Show with VBATransforming Power Point Show with VBA
Transforming Power Point Show with VBA
 
Visual Studio and Xamarin: The future of app development
Visual Studio and Xamarin: The future of app developmentVisual Studio and Xamarin: The future of app development
Visual Studio and Xamarin: The future of app development
 
Selenium
SeleniumSelenium
Selenium
 
Java Custom Annotations- Part1
Java Custom Annotations- Part1Java Custom Annotations- Part1
Java Custom Annotations- Part1
 
Exception handling
Exception handlingException handling
Exception handling
 
AWS Lambda Hands-on: How to Create Phone Call Notifications in a Serverless Way
 AWS Lambda Hands-on: How to Create Phone Call Notifications in a Serverless Way AWS Lambda Hands-on: How to Create Phone Call Notifications in a Serverless Way
AWS Lambda Hands-on: How to Create Phone Call Notifications in a Serverless Way
 

Similar to Chapter 9

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
YamunaS38
 
Data validation in silverlight
Data validation in silverlightData validation in silverlight
Data validation in silverlight
msarangam
 
ASP.NET Session 10
ASP.NET Session 10ASP.NET Session 10
ASP.NET Session 10
Sisir Ghosh
 

Similar to Chapter 9 (20)

2310 b 07
2310 b 072310 b 07
2310 b 07
 
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
 
OLT open script
OLT open script OLT open script
OLT open script
 
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
 
Data validation in silverlight
Data validation in silverlightData validation in silverlight
Data validation in silverlight
 
Wheels
WheelsWheels
Wheels
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
 
Selenium ide material (2)
Selenium ide material (2)Selenium ide material (2)
Selenium ide material (2)
 
ASP.NET Session 10
ASP.NET Session 10ASP.NET Session 10
ASP.NET Session 10
 
Asp.net validation
Asp.net validationAsp.net validation
Asp.net validation
 
Test automation using selenium presented by Quontra Solutions
Test automation using selenium presented by Quontra SolutionsTest automation using selenium presented by Quontra Solutions
Test automation using selenium presented by Quontra Solutions
 
Selenium ide material (1)
Selenium ide material (1)Selenium ide material (1)
Selenium ide material (1)
 
validation
validationvalidation
validation
 
What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft What are Anypoint Validations With Mulesoft
What are Anypoint Validations With Mulesoft
 
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
 
Chapter 3 (validation control)
Chapter 3 (validation control)Chapter 3 (validation control)
Chapter 3 (validation control)
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Project1 CS
Project1 CSProject1 CS
Project1 CS
 
Ch3- Java Script.pdf
Ch3- Java Script.pdfCh3- Java Script.pdf
Ch3- Java Script.pdf
 
Project1 VB
Project1 VBProject1 VB
Project1 VB
 

More from application developer (20)

Chapter 26
Chapter 26Chapter 26
Chapter 26
 
Chapter 25
Chapter 25Chapter 25
Chapter 25
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Assignment
AssignmentAssignment
Assignment
 
Next step job board (Assignment)
Next step job board (Assignment)Next step job board (Assignment)
Next step job board (Assignment)
 
Chapter 19
Chapter 19Chapter 19
Chapter 19
 
Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Week 3 assignment
Week 3 assignmentWeek 3 assignment
Week 3 assignment
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
C # test paper
C # test paperC # test paper
C # test paper
 
Chapter 8 part2
Chapter 8   part2Chapter 8   part2
Chapter 8 part2
 
Chapter 8 part1
Chapter 8   part1Chapter 8   part1
Chapter 8 part1
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Chapter 9

  • 1. • Understanding Validation • Validation Controls • BaseValidator Class Properties • Validator Specific Properties • Validating with Regular Expressions • Regular Expression Characters • Commonly used Regular Expressions • Validation Summary Control • Manual Validation • Validation Groups
  • 2. Validation means ensuring that the data inserted into an application satisfies defined formats and other input criteria. Some possible mistakes a user can make: • Users might ignore an important field and leave it blank. • Users might try to type a short string of nonsense to circumvent a required field check. • Enter a nonnumeric character in a number field. • Malicious users might try to exploit a weakness in your code by entering carefully structured wrong values
  • 3. ASP.NET provides five validator controls. Four are targeted at specific types of validation, while the fifth allows you to apply custom validation routines
  • 4. All the validation controls are found in the System.Web.UI.WebControls namespace and inherit from the BaseValidator class. Property Description ControlToValidate Identifies the control that is to be validated Error Message If validation fails, the validator control can display a text message set by this property ForeColor By changing the ForeColor, you can make the error message stand out Display Dynamic, Static or None IsValid Returns true or false depending on whether it succeeded or failed Enabled When set to false, automatic validation will not be performed for this control when the page is submitted EnableClientScript If set to true, ASP.NET will add JavaScript and DHTML code to allow client-side validation on browsers that support it.
  • 5.
  • 6. One of ASP.NET’s most powerful validation controls is the RegularExpressionValidator, which validates text by determining whether it matches a specific pattern. 333sddd s represents any whitespace character (such as a space or tab). d represents any digit You can use the plus (+) sign to represent a repeated character. For example, 5+7 means “one or more occurrences of the character 5, followed by a single 7.” The number 57 would match, as would 555557 The following expression would match any word that starts with a letter from a to f, contains one or more “word” characters (letters), and ends with ing—possible matches include acting and developing. [a-f]w+ing
  • 7.
  • 8.
  • 9. In some modern browsers, ASP.NET automatically adds JavaScript code for client-side validation. In this case, when the user clicks a CausesValidation button, the same error messages will appear without the page needing to be submitted and returned from the server. This increases the responsiveness of your web page. However, even if the page validates successfully on the client side, ASP.NET still revalidates it when it’s received at the server.
  • 10. What happens when the user clicks a button : • If CausesValidation is false, ASP.NET will ignore the validation controls, the page will be posted back, and your event handling code will run normally. • If CausesValidation is true (the default), ASP.NET will automatically validate the page when the user clicks the button. It does this by performing the validation for each control on the page. If any control fails to validate, ASP.NET will return the page with some error information. Your click event handling code may or may not be executed. Use IsValid property in a conditional logic and write event handling code inside it.
  • 11. Accommodates all the error messages from all the validation controls at a suitable location normally at the bottom of the page. Error messages from all the validators are hided by setting their Display property to None. When you run the page, you won’t see any dynamic messages as you enter invalid information and tab to a new field. However, when you click the OK button, the ValidationSummary will appear with a list of all error messages. It automatically retrieves the value of the ErrorMessage property from each validator
  • 12. In some cases, you’ll want to display a full message in the summary and some sort of visual indicator next to the offending control You can use this technique with the help of the Text property of the validators. Ordinarily, Text is left empty, and the validator doesn’t show any content in the web page. However, if you set both Text and ErrorMessage, the ErrorMessage value will be used for the summary while the Text value is displayed in the validator. Of course, you’ll need to make sure you aren’t also setting the Display property of your validator to None.
  • 13. Manual validation is when you disable validation and perform the work on your own. This allows you to create a specialized error message of your own. You can create manual validation in one of three ways: I. Use your own code to verify values. In this case, you won’t use any of the ASP.NET validation controls. II. Disable the EnableClientScript property for each validation control. This allows an invalid page to be submitted, after which you can decide what to do with itdepending on the problems that may exist. III. Add a button with CausesValidation set to false. When this button is clicked, manually validate the page by calling the Page.Validate() method. Then examine the IsValid property, and decide what to do.
  • 14. Every control that provides a CausesValidation property also includes the ValidationGroup property. In some situations you might have several distinct groups of controls, possibly in separate panels and you may want to perform validations separately. To create a validation group, you need to set the ValidationGroup property of every control in the same logical group with the same descriptive string.