Click here to Skip to main content
15,886,806 members
Everything / Validation

Validation

validation

Great Reads

by Edwyn Amador
Handles and validates input typing and pressed keys in TextBox, RichTextBox and ComboBox, displaying custom balloon tips messages
by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
In this blog, we will explore a trick to validate whether any CheckBox inside one CheckBoxList is checked or not.
by vladimir husnullin
Web development using JSON is simple
by Chris Copeland
A managed library for automated dependency injection, contract validation, and custom aspect-oriented decorator implementations

Latest Articles

by Han Bo Sun
Several ways of form field validation using Angular framework
by siliconvideo
This StringBox control implements keystroke validation using regular expressions and a touch of glue logic
by Chris Copeland
A managed library for automated dependency injection, contract validation, and custom aspect-oriented decorator implementations
by siliconvideo
A NumberBox class for number entry, display, range limits and keystroke validation including binary

All Articles

Sort by Score

Validation 

17 Jul 2019 by Edwyn Amador
Handles and validates input typing and pressed keys in TextBox, RichTextBox and ComboBox, displaying custom balloon tips messages
24 Feb 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
In this blog, we will explore a trick to validate whether any CheckBox inside one CheckBoxList is checked or not.
24 Nov 2015 by vladimir husnullin
Web development using JSON is simple
9 Jun 2020 by Chris Copeland
A managed library for automated dependency injection, contract validation, and custom aspect-oriented decorator implementations
13 Jul 2014 by DiponRoy
Knockout Validation Error Message & Bootstrap v3.2 input-group
11 Nov 2015 by Jeroen Richters
This article describes a validation framework for MVVM based WPF controls.
16 Dec 2016 by Dilip Nandakumar
Extending Data Annotations library to support conditional validation in WPF
21 Jan 2020 by kr.is
How to create a simple validation attribute using C#
14 Jul 2012 by OriginalGriff
Google is a marvellous tool. But only if you actually bother to use it...Google[^]Top hit: How to Restrict user to enter only alphabates in TextBox by javascript in asp.net[^]In future, please try to do at least basic research yourself, and not waste your time or ours.
30 Jul 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
We will explore the technique in jQuery to validate the ASP.NET GridView.
28 May 2015 by Shivprasad koirala
In this blog we will try to understand how we can prevent and fine tune XSS(Cross Site Security) security attacks in ASP.NET MVC.
22 Jul 2020 by siliconvideo
This StringBox control implements keystroke validation using regular expressions and a touch of glue logic
5 Feb 2011 by fjdiewornncalwe
Try using the String.IsNullOrEmpty method. MSDN Documentation.It is likely that your FormattedValue equals string.Empty. An empty string is still a value so IsNothing won't work and IsDBNull won't work because the string value won't equal System.DBNull.Value.
15 Jul 2012 by Mohamed Mitwalli
Hi , Did you noticed that you post the same Question www.codeproject.com/Answers/422080/how-to-validate-textbox-with-previous-year[^]Go and Check there it's already AnswerBest RegardsM.Mitwalli
29 Jan 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Please follow the solution in How to validate textbox inside gridview to accept numeric values only[^].HTML:JAVASCRIPT://Restrict the user to key-in chrectors and other special...
3 Jul 2014 by DiponRoy
How to use Ajax validation in Knockout
3 Nov 2014 by Sergey Alexandrovich Kryukov
I don't know what do you want to achieve and why, but '+' is a part of Regular Expression syntax, so the only possible problem I can see is knowing that you can escape any character, in this case, '\+'. I did not see this combination of two characters in your Regex sample, that makes me think...
9 Jan 2016 by Wendelius
As far as I can see you check if the text boxes are empty but you don't exit from the calling method if validation fails.In other words the validation should be something likePublic Function CheckEmptyTextbox(ByVal groupbox As GroupBox) As Boolean Dim txt As Control For...
3 Jan 2023 by Han Bo Sun
Several ways of form field validation using Angular framework
15 Jul 2020 by ||Memo||
Guys i found the solution. public class ValidatorTool { public static void FluentValidate(IValidator validator, object entity) { var context = new ValidationContext(entity); var result...
7 Dec 2009 by Pete O'Hanlon
I would look at using the KeyPress event on the textbox and set e.Handled=true if the key was a spacebar (e is the KeyPressEventArgs for the event handler). Your code might look something like this:private void TextBox1_KeyPress(object sender, KeyPressEventArgs e){ e.Handled = e.KeyChar ==...
7 Dec 2009 by jasonpang2011
To add onto the answer above, the KeyPress event handler won't work unless you set KeyPreview to true. The KeyPreview property is on the Windows Form (click your form, look to the property box to the right, find KeyPreview, and set it to True). Or you can manually add the following to the...
7 Dec 2009 by AspDotNetDev
VB does not use a double equal sign to test for equality. It only uses a single equal sign. Try:e.Handled = (e.KeyChar = " ")Also, it doesn't use semicolons to end lines.
5 Feb 2011 by OriginalGriff
Use the DataGridViewCellValidatingEventArgs.FormattedValue property[^]
22 Feb 2011 by imsauravroy
A basic introduction on how to use data annotations for validating MVC models, which solves basic validation issues
7 Jul 2011 by Sergey Alexandrovich Kryukov
First of all, even if you implement such behavior, it cannot be called "validator". A "validator" is something which validates data after it is entered, but you want to filter out the input (selection) itself.I fear to say such behavior is too far from expected UI behavior and would be very...
9 May 2012 by member60
Simple ! Set Display="None" in the Validator tag as: Name : 
11 Jun 2012 by taha bahraminezhad Jooneghani
A custom validation control for FileUpload controls that validate like required validator, and have two more methods for extensions and file size!
10 Sep 2012 by sanwar_mal_jat
Hi dude use ValidationGroup property as like in aspx page TxtStudentName -> ValidationGroup ="stu"TxtStuPassword -> ValidationGroup ="stu"BtnStudentSubmit -> ValidationGroup ="stu"TxtTeacherName-> ValidationGroup ="teac"TxtTeachPassword-> ValidationGroup...
3 Apr 2013 by Prasad Khandekar
Hello,Rather than attaching the validation engine to a form you can use .validate method in your own submit handler. That way you can chose to take an appropriate action based on the return value. See doc here[^]Regards,
3 Jul 2013 by santosh_131
If the cell has to be checked for both the conditions try the following code:If (e.ColumnIndex = 0) Then 'checking value for column 1 only Dim cellData As Integer IF Not DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value is DBNull.Value Then If...
4 Oct 2013 by Ranesh M Raj
validate.js[^][Edit member="Tadit"]Link text added to reflect the Article/QA title.[/Edit]
20 Feb 2014 by Sergey Alexandrovich Kryukov
Please see my comment to the question.You just need to learn System.DateTime and methods of parsing of string into date data. Please see all the methods named Parse, ParseExact, TryParse and TryParseExact (and avoid using Convert, in most cases; after all, this is parsing, not...
6 May 2014 by CHill60
Try this ^(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,15}$Which I adapted after typing "Password" into the search engine at Regxlib.com[^]
7 May 2014 by Peter Leow
It has got nothing to do with regex, just use javascript to validate before submissioncheck-box-validation-for-atleast-one-check-box-should-cheked-in-asp-net[^]
26 May 2014 by Tkach Aleksey
WPF Gmail-style emails input control using C#, with email validation
1 Jul 2014 by Nguyen.H.H.Dang
Try this :Email Address Validation Using Regular Expression[^]That link show you how to check if input is an valid Email Address, but if you just wanna use Gmail or Yahoo, try this :"\w+([-+.]\w+)*@(yahoo|gmail)\.com)"
22 Oct 2014 by CHill60
Let's deal with TxtEmail_Validating first...All those checks that could finally lead to the message "Email cannot be left blank" are a waste of time - if you choose an appropriate regex to test against.But if you were going to leave them in, you need to exit appropriately once you have...
15 Sep 2015 by Andy Lanng
HTML 5 supports pattern and number type:Note: The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.
20 May 2016 by George Jonsson
Regular expressions are not the best tool for this, because you will have nested parts of your input text.In this case it with be more robust to use a parser, but that has a bit of a learning threshold. ANTLR4 is a free parser originally for Java, but it has a version for C# as well. See...
30 Nov 2016 by Karthik_Mahalingam
try like thisint value1 ,value2; bool isValid1 = int.TryParse(textbox1.Text, out value1); bool isValid2 = int.TryParse(textbox2.Text, out value2); if (isValid1 && isValid2) { if (value1 > value2) { // your...
23 Dec 2017 by OriginalGriff
If in doubt, google: validate postcode ( british) - Google Search[^] This links to Wikipedia: Postcodes in the United Kingdom - Wikipedia[^] which includes the UK Government validation Regex ... In future, please try to do at least basic research yourself, and not waste your time or ours -...
7 Mar 2019 by Gerry Schmitz
Considering that a work book can contain practically anything, I don't see how anyone can come up with a "generic" solution to satisfy your curiosity as to the "validity" of its content. Better you come up with a "standard" workbook that you insist the client uses. If that's not possible, then...
10 Dec 2009 by nGrafix
Hi guys,I finished my project in VB.NET (VS.NET 2008). This project supports three languages; English (UK), Kazakh (Kazakstan) and Hausa (Nigeria). The program allows the user to swtich between the languages at runtime via ComboBox's SelectedIndexChanged event.The problem is Hausa (a...
10 Dec 2009 by MaasOne
Check the Windows version from System.Environment-class. Vista has version 6 and Win 7 has (what a surprise :)) version 7. Private Function IsVistaOrHigher() As Boolean Return Environment.OSVersion.Version.Major >= 6 End FunctionMaas
8 Feb 2010 by William Winner
Or maybe this was asked on an application? Or maybe this is homework for a class?If you posted your response, it might get more replies.
15 Mar 2010 by goldeneyeonline
Hi nishantsagar83!Thank you very much for your answer!Since I usually only use the sourcecode tab, i was really hoping this would do it... but it didn't:(I mean, even when i click on the error text in design view, then my cursor jumps to the function for the Custom Validator, but it still...
28 Nov 2010 by thedude9
Thanks Uwe, yes that is a great book. But it doesn't have anything about validation.
12 Dec 2010 by thedude9
How do you localize validation messages?Assume business layer validation.I am thinking of "error codes + target name", that could be translated to some localized message in the presentation layer. A good idea?Can someone please share good practices?
5 Feb 2011 by Estys
You handle the wrong event.It must be :private void dgvPhysCME_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) Handles dgvPhysCME.CellValidatingThe DataGridViewCellValidatingEventArgs has a Cancel property.Cheers
8 Feb 2011 by thomas struss
Hey guys, I'm really new to C++ and I'm trying to figure out how to validate a char var--to see if it's an int between 1 and 6, basically. The program I have so far catches all the exceptions I want it to except for numbers over 9 and negative numbers.When the number entered is 9 or higher it...
8 Feb 2011 by Yusuf
The easiest way is to change your input to int. After that life will be a whole lot easier int myInt; myInt = atoi (choice);SEE Cplusplus[^] and MSDN[^] for details
10 Feb 2011 by Aescleal
There's a simple C++ idiom you can use to read an object of any type with an extraction operator and check to see if it's been read successfully. It's only a couple of lines:int n = 0;if( std::cin >> n ){ std::cout
10 May 2011 by Om Prakash Pant
One option is to store the existing data in javascript variables and when form is submitted, compare the data. If the data is same then show alert box to user.Another option is to use hidden fieldand comparing the data.you can also submit the form and do the comparision and show the...
1 Jan 2012 by Abhinav S
If you want to use Javascript, here[^] is a sample article that you can look at.You can also look at integrating validation controls with the gridview at runtime as discussed here[^].
12 Jan 2012 by Addy Tas
Hi,From the trail I can't directly figure out if you're just not happy with the frequency of synchronous call and/or you can't get the async to work. If the latter is the case I suggest that you post the non working code.Anyway what may be of interest for you is to check out a third...
1 Feb 2012 by Sanjay K. Gupta
1. for code var result1 = args.Value (intelisense not supported)2. use var rsult2 = document.getElementById('').value; instead ofvar rsult2 = document.getElementById("ddl1").value;
1 Feb 2012 by Sarvesh Kumar Gupta
Hi,ddl does not works like this.use below code for access ddl in JS.ddlObj = document.getElementById('');ddlVal = ddlObj.options[ddlObj.selectedIndex].value;
15 Feb 2012 by Jeevitha royapathi
HI,Add different validation group for two requiredfieldvalidtor and to respective linkbuttons..like
1 Mar 2012 by Sunasara Imdadhusen
Hi All,Now i resolved issue using following code. I have replaced following linetxtTextBox.SetBinding(TextBox.VisibilityProperty, new Binding("Redactable") { Source = this, Converter = new BoolToVisibilityConverterReverse() });with this.MapBinding(RestrictedControl.ValueProperty,...
7 Mar 2012 by Saeid.Babaei86
i have a problem . if i want to save html tags icluded text such as i get below problem :" A potentially dangerous Request.Form value was detected from the client... "i dont want to disable page ValidationRequest . what i do ?
7 Mar 2012 by walterhevedeich
See here:ASP.NET 4.0 potentially dangerous Request.Form value was detected[^]
7 Mar 2012 by Ganesan Senthilvel
You should use JavaScript (or a server-side script) to properly escape any user input. Here's another JavaScript function you could tryString.prototype.escapeHTML = function () { return( this.replace(/>/g,'>'). replace(/
9 May 2012 by Abhi KA
try this linkhttp://www.aspxcode.net/free-asp-net-validation-source-code.aspx?Topics=How%20to%20Use%20ValidationSummary[^]
25 Jun 2012 by Sanjay Kunjam
Try this..Text box to accept only number[^]
25 Jun 2012 by Prasad_Kulkarni
Try this:void NumberValidation(object sender, KeyPressEventArgs e) { if ((e.KeyChar >= 48 && e.KeyChar
7 Jul 2012 by Mohd Imran Saifi
You Can use it by two ways:-1. Javascriptjust add this script on page's HTML sidefunction checking(){ var check1 = document.getElementById("").length; if(var4) { alert('Please Enter Only 4 digit no.'); ...
7 Jul 2012 by OriginalGriff
Add a check for the Enabled property:if ((myControl.GetType() == typeof(TextBox)) || (myControl.GetType() == typeof(ComboBox))) { //myControl.Text = myControl.Text.Trim(); if (myControl.Enabled && string.IsNullOrWhiteSpace(myControl.Text)) { ...
9 Jul 2012 by Destiny777
There are many solutions to this problem.You want to keep it simple and easy to understand!Try writing the pseudo code first then walk through it on paper before you code it to see if you really understand how it works. If your pseudo code does not work, then clean it up until it does...
15 Jul 2012 by Sandeep Mewara
There are ways to make this happen, using regular expression, JavaScript validation, etc. I would prefer Masked Textbox for it, something like: Enhanced Textbox Control[^]
15 Jul 2012 by Abdul Quader Mamun
var value = "a";var reg = new RegExp("[A-Za-z]");if (!reg.test(value)) { return false;}try with this.Thanks,Mamun
15 Jul 2012 by S.Dwaik
you must add from Toolbox in Validation and select RequiredExpressionValidator;and in properties "ControlToValidat" select filed name ex: Textbox1and select Expression mask from ValidationExpression for alphabets "\w+"S.Dwaik
15 Jul 2012 by abhinavvijay
function onlyAlphabets(e, t) {try {if (window.event) {var charCode = window.event.keyCode;}else if (e) {var charCode = e.which;}else { return true; }if ((charCode > 64 && charCode 96 && charCode
16 Jul 2012 by Mohamed Mitwalli
Hi , Check this solution , Just use CompareValidator ValueToCompare="2012" Operator="GreaterThan" only this proprieties you have to care about to cause the validation and ErrorMessage to Give the Error message you want . ...
15 Jul 2012 by Pankaj Nikam
You can use CompareValidator for that. Follow the steps:1. Drag and drop a CompareValidator from the toolbox to a suitable place you like.2. Set the Operator to GreaterThan3. Set the ControlToValidate property to the TextBox (which has the year)4. Set the ValueToCompare on the Page...
20 Jul 2012 by Christian Graus
The most obvious way to do this, is to have a javascript method that is called in the onblur, because that is easy to write and to put in to the template for your gridview, so it's called for each textbox. Using a decent date control makes more sense, but if you're stuck with a textbox, that's...
26 Jul 2012 by Raghunatha_Reddy_S
Try this function validate(){var n=document.getElementById("name").value;var q=document.getElementById("quantity").value;var p=document.getElementById("price").value;var na=/^[a-z ]*$/;var no=/^[0-9 ]*$/; if (!na.test(n)) { alert("Please enter valid name."); ...
26 Jul 2012 by AshishChaudha
Try this function CalculateGPer() { var Form = document.frmReg; var txt1= Form.txtBox1.value; var txt2= Form.txtBox2.value; var addition1= (Number(txt1)+Number(txt2)); if(!isNaN(Per) &&...
3 Aug 2012 by _Amy
Hi,Try this:HTML:JAVASCRIPT://Restrict the user to key-in chrectors and other special charectorsfunction onlyNumbers(evt) { var e = event || evt; // for trans-browser...
10 Sep 2012 by Mohamed Mitwalli
Hi ,Check this Article http://www.codedigest.com/Articles/ASPNET/26_Validation_group_in_ASPNet_20.aspx[^]Best RegardsM.Mitwalli
11 Sep 2012 by Predator008
Hi Dear developers, I am having 2 textboxes which I want to check for string lenght (more than 2 characters) and for requirement. the problem is that I can't put this server-side validation in code behind of my page, instead I should call a function I should create in BLL file in my project. I...
12 Sep 2012 by _Amy
It's not possible to validate a HTML control using RequiredFieldValidator. If you want to validate your HTML control client side only then you need to use JavaScript.RequiredFieldValidator is used only for server controls.--Amit
1 Nov 2012 by Maciej Los
First of all, read these articles:http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.validation%28v=office.11%29.aspx[^]http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.validation_properties%28v=office.11%29.aspx[^]If you would like to use...
24 Nov 2012 by Mohd Imran Saifi
You have to specify validation group for each Section. Try this.; Untitled Page ...
17 Jan 2013 by rakesh1503
hi,what i can suggest you to go by is the code like below:suppose,we have this sort of design ...
21 Apr 2013 by Thanks7872
Go through these links.Password conditionsRegular Expressions reference
21 Apr 2013 by Karthik Harve
Hi,you can make use of regular expressionsrefer7 Regular Expressions a C# Developer Must Know[^]Using Regular Expressions in C# .NET[^]try with below expression.^.*(?=.{6,})(?=.\d)(?=.{5,}[a-z,A-Z]).*$ above expression validate for, 1 numeric, 5 alphabets and maximum 6...
21 Apr 2013 by CPallini
As an alternative to regulare expressions. A simple approach would be:validate length: if password is too short or too long, reject itvalidate charactersFurther details for point 2: set num_count = 0, alpha_count = 0, then, for each character of the password, ifit is a numeric...
25 Jun 2013 by Ron Beyer
If CType(cellData, int) cellData ThenAssuming cellData is a numeric value, that should work.
8 Jul 2013 by ArunRajendra
You should be able to find it in this site. http://regexlib.com/[^]
8 Jul 2013 by Thanks7872
Try this ^[A-Za-z0-9- ]+$Regards.. :laugh:
21 Jul 2013 by Maciej Los
If your DGV is bind with MS Excel Sheet data (using OLEDB), then probably, default value of cell should be DBNull.Value.
24 Jul 2013 by Winston Madiano
You can use DatagridviewCellFormating Event if you want to change the back color of you datagridview row based on cell value.Ex:On your DataGridView1_CellFormatting EventDim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)Dim obj As Object = row.Cells("ColumnName").Value...
2 Aug 2013 by Clifford Nelson
Not sure this will help you, but here is a CodeProject article: Validation in Windows Presentation Foundation[^]
4 Sep 2013 by Menon Santosh
check this articlehttp://stackoverflow.com/questions/4068373/center-a-popup-window-on-screen[^]
14 Sep 2013 by Rohit kumar6210
Any one Please help me to solve the following error ? Please tell me why the following error occurs ????Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation...
11 Oct 2013 by ASP.NET Community
ASP.NET Validation Controls are powerful server controls that are used for validating user input.  These controls provides both server side and
11 Oct 2013 by ASP.NET Community
The CompareValidator control compares the value of one control to another, or to an explicit value in the control's ValueToCompare property.
21 Oct 2013 by bjdestiny
For Range Validator refer ASP.NET RangeValidator Control[^] and follow this code
23 Oct 2013 by Member 10321925
I have 3 TextBoxes (Id,Name and Salary)Id and salary should be integers and Name is only charecters.I need validations for my TextBox as i enter wrong charecters or integers it should show error and also can i do it this in only xaml without codebehind ? I'm new to Wpf and validation please help...