Validation Controls - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Validation Controls

Description:

The following web.config will allow error messages to be displayed ... [abcd] Matches any character included between the brackets. ... – PowerPoint PPT presentation

Number of Views:296
Avg rating:3.0/5.0
Slides: 18
Provided by: saxserv
Category:

less

Transcript and Presenter's Notes

Title: Validation Controls


1
Validation Controls
2
Outline
  • Review of web controls
  • Use validation controls to implement validations
    for a web page
  • Describe the use of the IsValid property of a
    page and the Validate method of a page

3
Page.IsPostBack
  • Page default object
  • Belongs to web page class
  • IsPostBack
  • A property of the web page class
  • Boolean variable
  • False when the page is displayed the first time
  • True the page is being redisplayed in response
    to a control event

4
Web.config
  • Upload and store the file at your folder on the
    server
  • It can control error message display
  • The following web.config will allow error
    messages to be displayed
  • lt!-- Web.Config Configuration File --gt
  • ltconfigurationgt
  • ltsystem.webgt
  • ltcustomErrors mode"Off"/gt
  • lt/system.webgt
  • lt/configurationgt

5
Validation Controls in ASP.NET
  • RequiredFieldValidator
  • CompareValidator
  • RangeValidator
  • RegularExpressionValidator

6
Common Properties of Validation Control
  • ControlToValidate The control the validator will
    check.
  • ErrorMessage The text message when validation
    fails.
  • IsValid It returns True or False depending on
    whether the validation succeeded or failed.

7
Required Field Validator
  • ltaspTextBox ID"txtName" runat"server"gtlt/aspTex
    tBoxgt
  • ltaspRequiredFieldValidator ID"RequiredFieldValid
    ator1"
  • runat"server"
  • ControlToValidate"txtName"
  • ErrorMessage"You must enter a name."gt
  • lt/aspRequiredFieldValidatorgt

8
Additional Properties of the Compare Validator
9
A compare validator that checks for a value
greater than zero
  • ltaspTextBox ID"txtQuantity" runat"server"gt
  • lt/aspTextBoxgtnbsp
  • ltaspCompareValidator ID"CompareValidator1"
  • runat"server"
  • ControlToValidate"txtQuantity"
    Type"Integer"
  • Operator"GreaterThan" ValueToCompare"0"
  • ErrorMessage"Quantity must be greater than
    zero."gt
  • lt/aspCompareValidatorgt

10
Compare Two Textboxes
  • ltaspTextBox ID"txtStartDate" runat"server"gtlt/as
    pTextBoxgtltbr /gt
  • ltaspTextBox ID"txtEndDate" runat"server"gt
  • lt/aspTextBoxgt
  • ltaspCompareValidator
  • ID"CompareValidator3" runat"server"
  • ControlToValidate"txtEndDate"
  • Operator"GreaterThan" Type"Date"
  • ControlToCompare"txtStartDate"
  • ErrorMessage
  • "End Date must be greater than Start
    Date."gt
  • lt/aspCompareValidatorgt

11
Additional Properties of the Range Validator
12
A range validator that checks for a numeric range
  • ltaspTextBox ID"txtDays" runat"server"gtlt/aspTex
    tBoxgt
  • ltaspRangeValidator ID"RangeValidator1"
    runat"server"
  • ControlToValidate"txtDays" Type"Integer"
  • MinimumValue"1" MaximumValue"14"
  • ErrorMessage"Days must be between 1 and
    14."gt
  • lt/aspRangeValidatorgt

13
Regular Expression
  • In computing, a regular expression, also called a
    pattern, is an expression that describes a set of
    strings
  • It provide a concise and flexible way to identify
    strings of text
  • Regular expressions can be used with regular
    expression validator to check whether the input
    data match a particular pattern

14
Common Regular Expression Items
  • \ Matches the character that follows.
  • \d Matches any decimal digit (0-9)
  • \w Matches any word character including letters,
    numbers, and underscore (a-z, A-Z, and 0-9).
  • \S Matches non-whitespace character
  • n Matches exactly n occurrences of the
    preceding element or group.
  • n, Matches at least n occurrences of the
    preceding element or group.
  • n,m Matches at least n but no more than m
    occurrences of the preceding element or group.

15
Common Regular Expression Items
  • abcd Matches any character included between the
    brackets.
  • abcd Matches any character that is not
    included between the brackets.
  • a-z Matches any characters in the indicated
    range.
  • Matches zero or more occurrences of the
    preceding element.
  • ? Matches zero or one occurrence of the
    preceding element.
  • Matches one or more occurrences of the
    preceding element.
  • Matches any of the elements separated by the
    vertical bar.
  • ( ) Groups the elements that appear between the
    parentheses to be treated as a single element.
    For example, (78) matches 78 and 787878

16
Examples
  • \d3 Three numbers
  • \w4,10 A password that must be between 4 to 10
    characters
  • \S4,10 A password that must be between 4 to 10
    characters, allowing special characters
    including asterisks, ampersands, etc.
  • \S_at_\S\.\S Check for an _at_ sign and dot (.) and
    allow non-whitespace characters

17
IsValid Property
  • Validation control
  • this property depends on whether the validation
    was successful
  • Page
  • this property to indicate whether all the input
    data is valid
Write a Comment
User Comments (0)
About PowerShow.com