Skip to main content

Posts

Showing posts with the label validation

RequiredFieldValidator to validate RadioButtonList in asp.net c#

RequiredFieldValidator to validate RadioButtonList RequiredFieldValidator validation control makes an asp.net web server input control like a mandatory field. Input control validation fails if the value of the control does not change from its initial value. So it will be a required field (input control) for submitting the web form. The user must input some value to pass the validation. You cannot pass validation by only entering space. You can set the RequiredFieldValidator InitialValue property to select another item except for the initial value for passing validation. You can set the ErrorMessage property value to display an error message when validation failed. This example demonstrates to you how can we validate RadioButtonList control using RequiredFieldValidator. This validation control makes RadioButtonList a mandatory (required) field. So the user must select (check) a list item from RadioButtonList to pass the validation and submit the for...

ASP.NET RegularExpressionValidator - Validate U.S. Social Security Number

RegularExpressionValidator to validate US Social Security Number The RegularExpressionValidator control validates whether the value of an associated input control matches the pattern specified by a regular expression. The following asp.net c# tutorial code demonstrates how we can validate a US Social Security Number. We used a RegularExpressionValidator control and a RequiredFiledValidator control to validate a specified United States Social Security Number. A RegularExpressionValidator control checks whether the value of an input control (as an example a TextBox) matches a pattern defined by a regular expression. The regular expression validation allows the asp.net c# developers to check for predictable sequences of characters, such as those in Zip Codes, telephone numbers, and emails. But there is an issue while validating using RegularExpressionValidator control. If the specified input control is left empty the regular expression va...

ASP.NET RegularExpressionValidator - Validate U.S. Phone Number

RegularExpressionValidator to validate US Phone Number The RegularExpressionValidator control validates whether the value of an associated input control matches the pattern specified by a regular expression. The following asp.net c# tutorial code demonstrates how we can validate a US Phone Number. In the below example, we validated a United States Phone Number by using a RegularExpressionValidator control. The RegularExpressionValidator control checks whether the value of an input control (such as a TextBox) matches a pattern defined by a regular expression. Regular expression validation allows the asp.net c# developers to check for predictable sequences of characters, such as those in Zip Codes, telephone numbers, and URLs. When the input control (such as a TextBox) is empty, the regular expression validation will succeed. So, if a value is required for the associated input control (such as a TextBox), the asp.net c# developers have...

ASP.NET RegularExpressionValidator - Validate U.S. Zip Code

RegularExpressionValidator to validate US Zip Code The RegularExpressionValidator control validates whether the value of an associated input control matches the pattern specified by a regular expression. The following asp.net c# tutorial code demonstrates how we can validate a US Zip Code. In this example, we will validate the United States Zip Code with RegularExpressionValidator web server control. The RegularExpressionValidator web server control checks whether the value of an input control such as TextBox matches a pattern defined by a regular expression. This type of validation allows the asp.net developers to check for predictable sequences of characters, such as those in Zip Codes, telephone numbers, and URLs. If the input control such as TextBox is empty, the regular expression validation will succeed. So, if a value is required for the associated input control (TextBox), the asp.net developers have to use a RequiredFieldValida...

Validate an URL using RegularExpressionValidator in asp.net c#

URL validation using RegularExpressionValidator The RegularExpressionValidator control validates whether the value of an associated input control matches the pattern specified by a regular expression. The following asp.net c# tutorial code demonstrates how we can validate an URL. Here we will validate an URL by using the RegularExpressionValidator web server control. The RegularExpressionValidator web server control checks whether the value of an input control matches a pattern defined by a regular expression. This type of validation allows asp.net developers to check for predictable sequences of characters, such as those in email addresses, telephone numbers, and URLs. If the input control is empty, the validation will succeed. So, if a value is required for the associated input control, asp.net developers have to use a RequiredFieldValidator control in addition to the RegularExpressionValidator control. The RegularExpressionVal...

Validate an email address using RegularExpressionValidator in asp.net c#

RegularExpressionValidator - Validate email address RegularExpressionValidator control determines whether an input control's entered value matches a pattern defined by a regular expression. This validation control is very useful to check predictable sequences of characters. RegularExpressionValidator mostly uses to validate email addresses, social security numbers, telephone numbers, postal (zip) codes, etc. You also need to add a RequiredFieldValidator control because RegularExpressionValidator cannot validate empty value control. The Visual Studio and visual web developer .net IDE can auto-generate RegularExpressionValidator validation expression. It is a very useful and time-saving feature of visual studio. when validation failed RegularExpressionValidator control shows a predefined error message. This example demonstrates how can we validate user-inputted email addresses by RegularExpressionValidator. When the user inputs the email ad...

ASP.NET - Using Button control with CausesValidation property

Button CausesValidation The Button web server control displays a push button control on the Web page. The Button lets users post a page to the server. The control triggers an event in server code that asp.net developers can handle to respond to the postback. The Button can also raise an event in the client script that developers can handle before the page is posted or that can run and then cancel the submission of the page. The following asp.net c# tutorial code demonstrates how we can use the Button control CausesValidation property with validator control. Here we used the RequiredFieldValidator control to validate TextBox. We also add two Button controls on a web page. We will validate the TextBox by clicking a Button control but for another Button control, we will skip the validation process. The asp.net c# developers can do this by using Button control’s CausesValidation property. When a page contains validator controls by default clicking a Button ca...

How to use ValidationSummary control in asp.net

ValidationSummary web server control ValidationSummary control allows us to display the summary of all validation errors. We can display validation errors summary inline of a web page or a message box or both by using ShowMessageBox and ShowSummary property value true or false. We can display validation messages as bulleted lists, single paragraphs, or only lists based on DisplayMode. We can set a header text for the validation summary. ASP.NET ValidationSummary control has many properties to design the error messages text as fore color, back color, border color, border style, border width, theme, skin, and after all CSS class. ValidationSummary allows a summary of all validation error messages from all validators in a single location. This example shows you how can we display all validation error messages as a summary using the ValidationSummary control. Here we use three text boxes and make them required fields using RequiredFieldValid...

ASP.NET - Using SetFocusOnError property in validation control

Set focus on error in validation The following asp.net c# tutorial code demonstrates how we can set the focus on error in validation. In this tutorial, we used the RequiredFieldValidator control to validate TextBox. In the RequiredFieldValidator web server control, we set focus on the error feature. The RequiredFieldValidator web server control makes the associated input control a required field. The RequiredFieldValidator SetFocusOnError property gets or sets a value that indicates whether the focus is set to the control specified by the ControlToValidate property when validation fails. The SetFocusOnError property value is a Boolean. This property value is true to set focus on the control specified by ControlToValidate when validation fails otherwise its value is false. The default is false. So the asp.net c# developers can enable focus on error feature by using this SetFocusOnError property in validation control. They just have to set the S...

ASP.NET Validation - How to disable client script

Disable client script in validation The following asp.net c# tutorial code demonstrates how we can disable the client script in validation. In this tutorial, we used a RequiredFieldValidator control to validate a TextBox. In the RequiredFieldValidator web server control, we disabled the client script. The RequiredFieldValidator web server control makes the associated input control a required field. The RequiredFieldValidator EnableClientScript property gets or sets a value indicating whether client-side validation is enabled. The EnableClientScript property value is a Boolean. This property value is true if client-side validation is enabled otherwise the value is false. The default value is true. So, using this EnableClientScript property, the asp.net developers can disable the client script while validating the web page. They just have to set this property value to false. The asp.net c# developers can use the EnableClientScript property...

How to validate a DropDownList in asp.net

DropDownList Validation DropDownList is an asp.net list web server control that allows us to select a single item from a drop-down list at a time. DropDownList control contains ListItem objects. The following asp.net c# example code demonstrates to us how can we validate a DropDownList control in a web form. When users submit a form without changing the selection of DropDownList items, then the first item is posted to the server as a selected item if there is no initial selected item. Normally web developers put an instruction-only item at the DropDownList items top such as an item with the text 'select an item' etc. So web developers need to ensure that users select an item from DropDownList control other than the first item. We can validate a DropDownList server control using the RequiredFieldValidator control. RequiredFieldValidator is an asp.net validation server control that makes the associated input control a required field. We ca...

ASP.NET CompareValidator - How to validate Data Type

Validate data type using CompareValidator The CompareValidator class compares the value entered by the user in an input control with the value entered in another input control or with a constant value. The following asp.net c# tutorial code demonstrates how we can validate a data type using CompareValidator. In this example code, we will validate the integer data type. We will check the user input an integer value for the age field or not using the CompareValidator. The CompareValidator ControlToCompare property gets or sets the input control to compare with the input control being validated. This property value is a String which is the input control to compare with the input control being validated. The default value is Empty. The asp.net c# developers have to use the ControlToCompare property to specify an input control, such as a TextBox control, to compare with the input control being validated. The CompareValidator Operator...

How to use CompareValidator control in asp.net

CompareValidator CompareValidator control compares user inputted value with another input control value or a constant value. CompareValidator validation success if the inputted value matches the criteria specified by the Operator, ValueToCompare, or ControlToCompare property. CompareValidator Type property indicates whether inputted value needs to be converted to a specified data type (string, date, currency, double, or integer). The controlToValidate property indicates which control needs to validate. ControlToCompare property indicates which control needs to compare with inputted value (such as TextBox value). ValueToCompare property indicates that you want to compare the inputted value with a constant value instead another control value. Don't put ControlToValidate and ValueToCompare properties together in a CompareValidator control. You can use any one property at a time. That means you can only compare with a control or compare with ...