Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5837991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:25:13+00:00 2026-05-22T11:25:13+00:00

I’m in the process of writing a simple form validation script, and wondered whether

  • 0

I’m in the process of writing a simple form validation script, and wondered whether it’s better practice (both in the scope of this script, and in general programming) to assume a success and test for failure, or whether it’s best to assume failure, then try to ensure each item is successful.

I’ve searched on the subject, only to be hit with a bunch of inspirational quotes, and am rather interested if there’s a case where it will make a difference and as such, if one method is better/more secure/more efficient then the other?

Currently I test in a manner like this:

validation = true

for each field
{
    if not validate(field)
    then validation = false
}

return validation

The only benefit I see in this particular case, is in the instance where there are no things to validate, the form submits.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:25:13+00:00Added an answer on May 22, 2026 at 11:25 am

    With only a cursory exploration of the problem, I think the question boils down to whether it’s optimal to your design to include or exclude data by default.

    Assuming a collection of values A, B and C, there are two possible criteria for the result to be accepted: 1. all values must be valid, or 2. no values must be invalid.

    In the first case, one would begin with the premise that the default result would be false until all values were validated and in the second, the default would be true until proved false by one invalid value.

    To illustrate, assume a form containing:

    First Name: [  ] (required)
    Last  Name: [  ] (required)
    Tel Number: [  ] (required)
    Email Addr: [  ]
    

    where the possible validations might be:

    First Name must not be empty and must contain alpha chars only.
    Last  Name must not be empty and must contain alpha chars only.
    Tel Number must not be empty, must contain numbers only, formatted as (xxx) xxx-xxxx.
    Email Addr if not empty, must be formatted as xxx@xxx.yyy, etc.
    

    This case is inclusive in that all validation rules must return true for the input to be acceptable. Thus the default value should be false until proven true.

    Now consider this partial form for sending an email message:

    Subject:  [  ]
    CC:       [  ]
    BCC:      [  ]
    Priority: [  ]
    

    Since all fields are optional, this is the exclusive case where it would make sense to start with the assumption that the data are valid until they are proven invalid by one unacceptable value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.