2} RegularExpressionValidator :-



This Control is used to check whether user entered data is within the required format or not    like EmailId format, Web Address format, Pin code Format, Phone Number Format etc.
 Properties with RequiredFieldValidator :-
 
1.     ControlToValidate
2.     ErrorMessage
3.     Text
4.     ValidationGroup
5.     Validation Expression

5)ValidationExpresssion:-This property is used to set or get the required expression value with which we want to compare the user entered data. If user entered data matches with the format give in validationExpresssion property then RegularExpressionValidator return true to the webpage otherwise will return false to the webpage.
 
Example with RegularExpreessionValidator:-
  • Create a new webpage
  • Design the webpage 




Select the RegularExpressionValidator and set the following Properties:-
(ID)                             ---      RE1

ControlToValidate        ---      txtEmailId

Text                             ---      Invalid MailIdFormat

ValidationExpresssion

  • Click on Ellipses  Button
  • Select Internet Email Address
  • Click on Ok

Write the following code for Submit Button

protected void btnSubmit_Click(object sender,EventArgs e)
{
        lblDisplay.Text = "Page Submitted";
}

  • Run the Application & Check

  • In the above Example if user is not entering EmailId& Click on Submit Button then page result will be submitted to the server
  • This is because Except RequiredFieldValidator no other Control capable of checking the Emptiness of the Control.
  • All other validation Controls will perform the validation if there is data available in the Control only to overcome this drawback we should also use RequiredFieldValidator like: 

              [Add RequiredFieldValidator to the above webpage]




      Set the following properties for RequireFieldValidator1:-

ID                                  ---      RF1

ControlToValidate           ---      txtEmailId

Text                               ---      Enter EmilId

    Write the following code for submit Button:-
         
protected void btnSubmit_Click (object sender, EventArgs e)
{
        lblDisplay.Text = "Page Submitted to the Server";
}

  • Run the WebPage  & Check


No comments:

Post a Comment