Questions tagged [validation]
Tags for questions related to validating data.
276
questions
582
votes
1
answer
75k
views
Is the use of "utf8=✓" preferable to "utf8=true"?
I have recently seen a few URIs containing the query parameter "utf8=✓". My first impression (after thinking "mmm, looks cool") was that this could be used to detect a broken character encoding.
So, ...
109
votes
25
answers
42k
views
How far should one take e-mail address validation?
I'm wondering how far people should take the validation of e-mail address. My field is primarily web-development, but this applies anywhere.
I've seen a few approaches:
simply checking if there is ...
70
votes
7
answers
26k
views
If functions have to do null checks before doing the intended behaviour is this bad design?
So I don't know if this is good or bad code design so I thought I better ask.
I frequently create methods that do data processing involving classes and I often do a lot of checks in the methods to ...
55
votes
10
answers
36k
views
Should a method validate its parameters? [duplicate]
Say you are designing a Square root method sqrt. Do you prefer to validate the parameter passed is not a negative number or do you leave it up to the caller to make sure the param passed is valid. How ...
51
votes
4
answers
25k
views
Where we should put validation for domain model
I still looking best practice for domain model validation. Is that good to put the validation in constructor of domain model ? my domain model validation example as follows:
public class Order
{
...
48
votes
8
answers
9k
views
Is it common practice to validate responses from 3rd party APIs?
I'm working on a PHP web application that depends on a few 3rd-party services. These services are well documented and provided by fairly large organisations.
I feel paranoid when working with ...
45
votes
8
answers
5k
views
Should I throw an exception in case of a meaningful value outside of the range or handle it myself?
I have written a struct that represents latitude/longitude coordinates. Their values range from -180 to 180 for longtitudes and 90 to -90 for lattitudes.
If a user of that struct gives me a value ...
40
votes
9
answers
48k
views
Constructor parameter validation in C# - Best practices
What is the best practice for constructor parameter validation?
Suppose a simple bit of C#:
public class MyClass
{
public MyClass(string text)
{
if (String.IsNullOrEmpty(text))
...
33
votes
5
answers
11k
views
Data input validation - Where? How much? [closed]
Data input validation always was quite an internal struggle to me.
On the verge of adding a real security framework and code to our legacy application rewrite project (which so far pretty much keeps ...
32
votes
21
answers
10k
views
Is Software Testing Really Needed?
I'm a student working on my B.E(CS) and my question is the following:
Is testing in the software field needed?
If we create a software with great care, then why should we test?
After testing can ...
32
votes
6
answers
39k
views
In which layer should validation be located?
I'm creating a Rest API using Spring Boot and I am using Hibernate Validation to validate request inputs.
But I also need other kinds of validation, for example when update data needs to checked, if ...
31
votes
7
answers
8k
views
Should I validate a method call's return value even if I know that the method can't return bad input?
I'm wondering if I should defend against a method call's return value by validating that they meet my expectations even if I know that the method I'm calling will meet such expectations.
GIVEN
User ...
27
votes
6
answers
7k
views
Is it ok to have validation layer before access control layer
I am creating an API strcutured web application and in this application we have different layers which are doing their own job.
First layer is Validation layer which validate user input and if it ...
25
votes
4
answers
6k
views
Is client-side validation really all that important, always? [duplicate]
Through the years I've worked in web development it's been ingrained in me that client-side validation is absolutely and completely necessary in all web applications. Seems to me like all the people ...
24
votes
6
answers
43k
views
What Special characters should one allow for a Phone Number?
So I am designing a webpage which will be used for global users, includes users from Canada, US, India, UK etc. I need to apply validations for this phone number field, but I'm not sure the best way ...
21
votes
4
answers
14k
views
Clean architecture validation in domain vs data persistence layer?
I'm studying up on clean and as a result am quite dramatically rethinking a great deal of how I design and write software.
I've thing I'm still wrestling with however, is for business rules like "on ...
20
votes
9
answers
2k
views
Is an 'if password == XXXXXXX' enough for minimum security?
If I create a login for an app that has middle to low security risk (in other words, its not a banking app or anything), is it acceptable for me to verify a password entered by the user by just saying ...
20
votes
6
answers
14k
views
Validation of the input parameter in caller: code duplication?
Where is the best place to validate input parameters of function: in caller or in function itself?
As I would like to improve my coding style, I try to find the best practices or some rules for this ...
19
votes
9
answers
23k
views
When should pointers be checked for NULL in C?
Summary:
Should a function in C always check to make sure it is not dereferencing a NULL pointer? If not when is it appropriate to skip these checks?
Details:
I've been reading some books about ...
19
votes
4
answers
7k
views
Managing client-side and server-side validations in one place
I'm 100% on board with the case that one should definitely use both client-side and server-side data validations.
However, in the frameworks and environments I've worked in, the approaches I've seen ...
19
votes
2
answers
22k
views
Data validation: separated class or not?
When I have a lot of data that needs to be validated, should I create a new class for the sole purpose of validation or should I stick with in-method validation?
My particular example contemplates a ...
16
votes
4
answers
821
views
Is validating HTML a thing of the past? [duplicate]
With us moving continually closer to HTML5 in terms of adoption, is writing HTML for validity something the web is rejecting, allowing us to straddle standards as the web continues to be in a ...
13
votes
5
answers
2k
views
For an ORM supporting data validation, should constraints be enforced in the database as well?
I have always applied constraints at the database level in addition to my (ActiveRecord) models. But I've been wondering if this is really required?
A little background
I recently had to unit test a ...
13
votes
6
answers
14k
views
How should I handle invalid user input?
I have been thinking about this issue for a while and I would be curious to have opinions from other developers.
I tend to have a very defensive style of programming. My typical block or method looks ...
13
votes
2
answers
4k
views
Where to validate domain model rules that depend on database content?
I'm working on a system that allows Administrators to define Forms that contain Fields. The defined Forms are then used to enter data to the system. Sometimes the Forms are filled by a human via a GUI,...
13
votes
3
answers
5k
views
Validation and authorization in layered architecture
I know you are thinking (or maybe yelling), "not another question asking where validation belongs in a layered architecture?!?" Well, yes, but hopefully this will be a little bit of a different take ...
12
votes
5
answers
1k
views
Strengthening code with possibly useless exception handling
Is it a good practice to implement useless exception handling, just in case another part of the code is not coded correctly?
Basic example
A simple one, so I don't loose everybody :).
Let's say I'm ...
12
votes
4
answers
1k
views
How defensive should we be?
We've been running Pex over some code, and it has been showing some good things (well bad things, but showing them before it gets to production!).
However, one of the nice things about Pex is that it ...
12
votes
3
answers
5k
views
IValidatableObject vs Single Responsibility
I like the extnesibility point of MVC, allowing view models to implement IValidatableObject, and add custom validation.
I try to keep my Controllers lean, having this code be the only validation ...
12
votes
2
answers
3k
views
Where should you validate the state of "other" aggregates?
Scenario:
A customer places an order, then, after receiving the
product, provides feedback on the order process.
Assume the following aggregate roots:
Customer
Order
Feedback
Here are the business ...
11
votes
3
answers
2k
views
How to perform input validation without exceptions or redundancy
When I'm trying to create an interface for a specific program I'm generally trying to avoid throwing exceptions that depend on non-validated input.
So what often happens is that I've thought of a ...
11
votes
2
answers
28k
views
Name validation best practices
I have a form and I was wondering about best practices when validating names (specifically throwing out characters which do not typically make up a name e.g. 123%^*$£ though theoretically could) and ...
11
votes
2
answers
6k
views
Has anyone successfully used Windows Workflow for a Business Rules/Validation engine?
I was wondering if anyone has successfully used Windows Workflow Foundation for a BusinessRules/Validation engine, or if you know of some sample code or articles about this.
If you have used it ...
11
votes
1
answer
5k
views
Duck typing, data validation and assertive programming in Python
About duck typing:
Duck typing is aided by habitually not testing for the type of arguments in method and function bodies, relying on documentation, clear code and testing to ensure correct use.
...
11
votes
2
answers
8k
views
Command handlers and DDD
I have an ASP.NET MVC application, that uses a query service to get data and a command service to send commands. My question is about the command part.
If a request comes in, the command service uses ...
10
votes
5
answers
10k
views
Do you use both Client-side and Server-side validation techniques?
Do you use both Client-side and Server-side validation techniques side by side when validating input from a user, e.g. via a contact form?
If so, is it really necessary? Are you over engineering?
10
votes
6
answers
4k
views
How to ensure data consistency in system with multiple databases?
Let's say, in a rather big application suite with multiple more or less integrated products, data is stored across multiple databases. Some of them are SQL-ish DB clusters, some are MongoDB clusters.
...
10
votes
6
answers
4k
views
If the model is validating the data, shouldn't it throw exceptions on bad input?
Reading this SO question it seems that throwing exceptions for validating user input is frowned upon.
But who should validate this data? In my applications, all validations are done in the business ...
10
votes
6
answers
6k
views
Why is it bad to use exceptions for handling this type of validation? It seems like it makes the code so much cleaner
I'm working on a .NET Core REST API and I'm writing a service class to create new user accounts. I have the following code:
public async Task<UserDto> RegisterNewUserAccount(...
9
votes
4
answers
5k
views
Is it a bad idea to do validation in the constructor?
Consider the following approach to validation of an API class (POJO or what have you, I mean a class which just acts as a container for some properties), we make all constructors private to the API ...
9
votes
1
answer
1k
views
Better to use error monad with validation in your monadic functions, or implement your own monad with validation directly in your bind?
I'm wondering what's better design wise for usability/maintainability, and what's better as far as fitting with the community.
Given the data model:
type Name = String
data Amount = Out | Some | ...
9
votes
5
answers
2k
views
Message validation in async messaging-based services
I'm looking for information on the best approach to message validation in asynchronous-messaging-based services (i.e. services that pull messages from some sort of message queue or broker, rather than ...
8
votes
2
answers
2k
views
What is best practice to handle whitespaces when letting the user edit the configuration, the name=value pairs?
For instance, you let the user define the notorious path variable. How do you interpret apppath = C:\Program Files\App?
This looks like a programming language adopted practice to ignore the white ...
8
votes
2
answers
968
views
How come verification does not include actual testing?
Having read a lot about this topic --- such as on this Software Testing Fundamentals site on verification and validation and Software Testing and Quality Assurance: Theory and Practice by Naik and ...
8
votes
1
answer
7k
views
Writing a valid test case for validating XMLs
How would I write a unit test, say JUnit, for validating an XML file?
I have an application that creates a document as an XML file. In order to validate this XML structure, do I need to create an XML ...
7
votes
8
answers
958
views
Do objects with validation logic in their domain really represent their real world counterparts?
I asked a question about whether validation behavior should be treated the same as other types of behavior in regard to the concept of OOP being "data + behavior". I got some good answers back that ...
7
votes
3
answers
5k
views
OOP: Behavior + Data, but what about 'validation' behaviors?
EDIT: Thanks for all the great answers! In reading these responses I realized that I'm approaching this from the wrong angle so I wrote a new question here.
I had this discussion with my superior ...
7
votes
2
answers
3k
views
How is the Trial Period for Softwares generally implemented?
I was always under the assumption that trial softwares write a registry value of the installation date and then the software makes a comparison of the current date of the system with the remaining ...
7
votes
3
answers
454
views
How to measure external quality of software
For my thesis, I am doing research into the characteristics of Behavior Driven Development (BDD). One of the BDD claims is that by specifying the requirements in a ubiquitous language together with ...
7
votes
4
answers
7k
views
With a REST API, is there a convention for clients validate a request without committing any changes?
This may be easiest to explain with an example use case.
Let's say I have an e-commerce site where users can add items to their shopping cart. When adding items to the cart, users can type in the ...