Click here to Skip to main content
11,704,315 members (46,435 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: I'm in a weird mood ... Pin
Richard MacCutchan14-Dec-12 3:41
mvpRichard MacCutchan14-Dec-12 3:41 
GeneralRe: I'm in a weird mood ... Pin
Roger Wright14-Dec-12 4:09
memberRoger Wright14-Dec-12 4:09 
GeneralHow do you do it... Pin
Marco Bertschi14-Dec-12 3:09
memberMarco Bertschi14-Dec-12 3:09 
GeneralRe: How do you do it... Pin
DeathByChocolate14-Dec-12 3:15
memberDeathByChocolate14-Dec-12 3:15 
JokeRe: How do you do it... Pin
Marco Bertschi14-Dec-12 3:18
memberMarco Bertschi14-Dec-12 3:18 
GeneralRe: How do you do it... Pin
DeathByChocolate14-Dec-12 3:19
memberDeathByChocolate14-Dec-12 3:19 
GeneralRe: How do you do it... Pin
Nagy Vilmos14-Dec-12 3:20
memberNagy Vilmos14-Dec-12 3:20 
GeneralRe: How do you do it... Pin
OriginalGriff14-Dec-12 3:42
mvpOriginalGriff14-Dec-12 3:42 
GeneralRe: How do you do it... Pin
d@nish 14-Dec-12 3:17
member d@nish 14-Dec-12 3:17 
GeneralRe: How do you do it... Pin
DeathByChocolate14-Dec-12 3:18
memberDeathByChocolate14-Dec-12 3:18 
GeneralRe: How do you do it... Pin
d@nish 14-Dec-12 3:23
member d@nish 14-Dec-12 3:23 
GeneralRe: How do you do it... Pin
Richard MacCutchan14-Dec-12 3:41
mvpRichard MacCutchan14-Dec-12 3:41 
GeneralRe: How do you do it... Pin
Marco Bertschi14-Dec-12 4:08
memberMarco Bertschi14-Dec-12 4:08 
GeneralRe: How do you do it... Pin
Marc Clifton14-Dec-12 3:52
protectorMarc Clifton14-Dec-12 3:52 
So, the first non-flippant response:

First, recognize that validating inputs is a "pattern" for which you might want a general purpose solution. Second, recognize that there are a variety of solutions that you may want to support, resulting in several kinds of implementations:

1) Use the input control to ensure that non-valid data is never entered - create specialized controls that let you do things like range checking, excluding invalid characters, validation by regex, etc.

2) Use metadata to specify in the code itself what the validation logic should be, either "constants" to specify things like ranges or "typeof" that instantiates a validator class containing a validation method.

3) If the class maps to a database, provide enough information to the underlying ORM to perform the validation when the record is created.

4) Use the database itself, either in the schema definition (which is limited) or with PL/SQL code and insert / update triggers.

5) Create a "class-schema", possibly in XML, which maps the fields of the class to methods or validation information.

6) Use self-validating types. Rather than "string", use a type that defines exactly what the behavior is that you want for that string. So, for example, you might have a type "Phone" that obviously is going to do very different validation than "surname."

Some of these approaches require reflection, some do not, and depending where the data needs to validated (on user input for example, or validating millions of records in a DB) the performance hit of reflection is acceptable, in other scenarios it is not, so you want something else.

My preference is to push the issue to the source - whatever is generating the data (user input, for example) should perform the validation there so that you can guarantee that the data being put into the object is already correct, and also to use more concrete types that define the validation, formatting, etc., rather than the more abstract and general-purpose types like "string" or "int".

Marc

AnswerRe: How do you do it... Pin
Ravi Bhavnani14-Dec-12 4:39
memberRavi Bhavnani14-Dec-12 4:39 
GeneralA little weekend- optimization contest Pin
VuNic14-Dec-12 2:47
memberVuNic14-Dec-12 2:47 
GeneralRe: A little weekend- optimization contest Pin
harold aptroot14-Dec-12 3:02
memberharold aptroot14-Dec-12 3:02 
GeneralRe: A little weekend- optimization contest Pin
_Peeves14-Dec-12 3:05
member_Peeves14-Dec-12 3:05 
GeneralRe: A little weekend- optimization contest Pin
Chris Meech14-Dec-12 3:07
memberChris Meech14-Dec-12 3:07 
GeneralRe: A little weekend- optimization contest Pin
Simon_Whale14-Dec-12 3:08
memberSimon_Whale14-Dec-12 3:08 
GeneralRe: A little weekend- optimization contest Pin
Chris Meech14-Dec-12 3:37
memberChris Meech14-Dec-12 3:37 
GeneralRe: A little weekend- optimization contest Pin
Big Daddy Farang14-Dec-12 6:12
memberBig Daddy Farang14-Dec-12 6:12 
GeneralRe: A little weekend- optimization contest Pin
Chris Meech14-Dec-12 6:50
memberChris Meech14-Dec-12 6:50 
GeneralRe: A little weekend- optimization contest Pin
DeathByChocolate14-Dec-12 3:20
memberDeathByChocolate14-Dec-12 3:20 
JokeRe: A little weekend- optimization contest Pin
VuNic14-Dec-12 3:30
memberVuNic14-Dec-12 3:30 
GeneralRe: A little weekend- optimization contest Pin
OriginalGriff14-Dec-12 3:09
mvpOriginalGriff14-Dec-12 3:09 
GeneralRe: A little weekend- optimization contest Pin
Simon_Whale14-Dec-12 3:12
memberSimon_Whale14-Dec-12 3:12 
GeneralRe: A little weekend- optimization contest Pin
DeathByChocolate14-Dec-12 3:16
memberDeathByChocolate14-Dec-12 3:16 
GeneralRe: A little weekend- optimization contest Pin
OriginalGriff14-Dec-12 3:24
mvpOriginalGriff14-Dec-12 3:24 
GeneralRe: A little weekend- optimization contest Pin
DeathByChocolate16-Dec-12 17:42
memberDeathByChocolate16-Dec-12 17:42 
JokeRe: A little weekend- optimization contest Pin
VuNic14-Dec-12 3:33
memberVuNic14-Dec-12 3:33 
GeneralRe: A little weekend- optimization contest Pin
OriginalGriff14-Dec-12 3:40
mvpOriginalGriff14-Dec-12 3:40 
GeneralRe: A little weekend- optimization contest Pin
John Simmons / outlaw programmer14-Dec-12 3:27
mvpJohn Simmons / outlaw programmer14-Dec-12 3:27 
GeneralRe: A little weekend- optimization contest Pin
VuNic14-Dec-12 3:28
memberVuNic14-Dec-12 3:28 
GeneralRe: A little weekend- optimization contest Pin
peterchen14-Dec-12 3:32
memberpeterchen14-Dec-12 3:32 
GeneralRe: A little weekend- optimization contest Pin
Marc Clifton14-Dec-12 3:54
protectorMarc Clifton14-Dec-12 3:54 
GeneralRe: A little weekend- optimization contest Pin
Dexterus14-Dec-12 4:15
memberDexterus14-Dec-12 4:15 
GeneralRe: A little weekend- optimization contest Pin
Bert Mitton14-Dec-12 4:24
memberBert Mitton14-Dec-12 4:24 
GeneralRe: A little weekend- optimization contest Pin
PIEBALDconsult14-Dec-12 21:40
memberPIEBALDconsult14-Dec-12 21:40 
GeneralRe: A little weekend- optimization contest Pin
PIEBALDconsult14-Dec-12 15:44
memberPIEBALDconsult14-Dec-12 15:44 
GeneralWhy is it that when I see "View Unanswered Questions" on the menu ... Pin
DeathByChocolate14-Dec-12 2:30
memberDeathByChocolate14-Dec-12 2:30 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
Nagy Vilmos14-Dec-12 2:42
memberNagy Vilmos14-Dec-12 2:42 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
DeathByChocolate14-Dec-12 2:48
memberDeathByChocolate14-Dec-12 2:48 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
ProgramFOX14-Dec-12 2:52
memberProgramFOX14-Dec-12 2:52 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
Simon_Whale14-Dec-12 3:02
memberSimon_Whale14-Dec-12 3:02 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
DeathByChocolate14-Dec-12 3:09
memberDeathByChocolate14-Dec-12 3:09 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
Simon_Whale14-Dec-12 3:11
memberSimon_Whale14-Dec-12 3:11 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
DeathByChocolate14-Dec-12 3:12
memberDeathByChocolate14-Dec-12 3:12 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
_Peeves14-Dec-12 3:07
member_Peeves14-Dec-12 3:07 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pin
d@nish 14-Dec-12 3:20
member d@nish 14-Dec-12 3:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 28 Aug 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid