Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts
Dropdownlist validation in Asp.net Using Required field validator

Dropdownlist validation in Asp.net Using Required field validator

Introduction:
Here I will explain how to Dropdownlist validation in Asp.net Using Required field validator.
In previous articles I explained validate email address using  code for validating checkbox in asp.net  In 
ASP.Net And Many Article Relating to Validation Now I Will   Explained  Dropdownlist validation in Asp.net Using RequiredField validator  In Asp.net.
To implement this one we need to write code as shown below in your aspx page
<asp:DropDownList  CssClass="dropdown" ValidationGroup="g1" 
ID="dropdown" runat="server" OnSelectedIndexChanged="dropdown_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="dropdown" ID="RequiredFieldValidator1"
ValidationGroup="g1" CssClass="dropdown" ErrorMessage="Select Dropdown"InitialValue="--Select Asprockers--" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>


dropdown.Items.Insert(0, "--Select Asprockers--"));
Code for Validating Checkbox in asp.net with required field validator

Code for Validating Checkbox in asp.net with required field validator

Above I have placed an ASP.Net Custom Validator besides the ASP.Net Checkbox control. For the ASP.Net Custom Validator I have specified the ClientValidationFunction property to a JavaScript function ValidateCheckBox which validates the whether the checkbox is checked or not.


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type = "text/javascript">
function ValidateCheckBox(sender, args) {
if (document.getElementById("<%=CheckBox1.ClientID %>").checked == true) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required" ClientValidationFunction = "ValidateCheckBox"></asp:CustomValidator><br />
<asp:Button ID="Button1" runat="server" Text="Submit"/>
</form>
</body>
</html>
Email Validation in Windows Application C#

Email Validation in Windows Application C#

System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");

//txtmail is name/object of textbox
            if (txtmail.Text.Length > 0){

//rEMail is object of Regex class located in System.Text.RegularExpressions
                if (!rEMail.IsMatch(txtmail.Text))
                {
                    MessageBox.Show("E-Mail expected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtmail.SelectAll();
                    e.Cancel = true;
                }

Popular Posts