Questions tagged [validation]

Tags for questions related to validating data.

Questions related to validating data. It could be data in a database, user input, messages from other processes, etc...

273 questions
580
votes
1 answer

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, is this a better way to resolve potential…
Gary
  • 24,420
  • 9
  • 63
  • 108
109
votes
25 answers

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 an "@" present, which is dead simple but of course…
Lauren
  • 1,259
  • 2
  • 8
  • 9
70
votes
7 answers

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 make sure I don't get null references or other…
WDUK
  • 2,032
  • 3
  • 13
  • 23
55
votes
10 answers

Should a method validate its parameters?

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 does your answer vary if the method/API is for…
Amit Wadhwa
  • 1,962
  • 1
  • 15
  • 20
51
votes
4 answers

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 { private readonly List _lineItems; …
adisembiring
  • 623
  • 1
  • 6
  • 6
46
votes
8 answers

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 responses from these API, which leads me to write…
44
votes
8 answers

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 outside of that range, I have 2 options: Throw an…
RaidenF
  • 1,499
  • 1
  • 13
  • 17
40
votes
9 answers

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)) throw new ArgumentException("Text cannot be…
MPelletier
  • 2,038
  • 1
  • 18
  • 27
32
votes
21 answers

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 we be sure that we have achieved this goal (the…
Ant's
  • 732
  • 6
  • 17
31
votes
6 answers

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 the company id doesn't exist I want to throw a…
fdarmanto
  • 411
  • 1
  • 4
  • 3
31
votes
7 answers

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 getUser(Int id) { User temp = new User(id); …
Didier A.
  • 1,327
  • 14
  • 10
30
votes
5 answers

Data input validation - Where? How much?

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 the card-castle-strong legacy security code and…
mdrg
  • 469
  • 1
  • 4
  • 7
27
votes
6 answers

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 passes the validation we move that to second layer…
Muhammad
  • 399
  • 3
  • 7
25
votes
4 answers

Is client-side validation really all that important, always?

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 in the profession are very adamant on using it…
Alternatex
  • 1,033
  • 2
  • 13
  • 24
23
votes
6 answers

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 to go about this. Some of the valid formats I can…
Ranger
  • 993
  • 1
  • 5
  • 12
1
2 3
18 19