Questions tagged [validation]

Validation is used to check data to make sure it fits whatever required specifications are set for it. Typically Validation is used in checking input data, and in verifying data before storage.

Data validation is the process of ensuring that a program operates on clean, correct and useful data. It applies rules or constraints to check for correctness, meaningfulness, and security of data that are input to the system.

The most common reasons for validation are to avoid entering data which violates a database schema, and to prevent unauthorized exploitation of a user interface.

Different kinds of validation

In evaluating the basics of data validation, generalizations can be made regarding the different types of validation, according to the scope, complexity, and purpose of the various validation operations to be carried out.

For example:

  1. Data type validation;
  2. Range and constraint validation;
  3. Code and Cross-reference validation; and
  4. Structured validation

Resources:

62584 questions
245
votes
15 answers

Cross field validation with Hibernate Validator (JSR 303)

Is there an implementation of (or third-party implementation for) cross field validation in Hibernate Validator 4.x? If not, what is the cleanest way to implement a cross field validator? As an example, how can you use the API to validate two bean…
Bradley Dwyer
  • 7,862
  • 5
  • 30
  • 28
237
votes
15 answers

How can I check if a single character appears in a string?

In Java is there a way to check the condition: "Does this single character appear at all in string x" without using a loop?
barfoon
  • 25,436
  • 24
  • 88
  • 136
235
votes
14 answers

Why a function checking if a string is empty always returns true?

I have a function isNotEmpty which returns true if the string is not empty and false if the string is empty. I've found out that it is not working if I pass an empty string through it. function isNotEmpty($input) { $strTemp = $input; …
bgosalci
  • 2,635
  • 2
  • 16
  • 8
235
votes
6 answers

How can I conditionally require form inputs with AngularJS?

Suppose we're building an address book application (contrived example) with AngularJS. We have a form for contacts that has inputs for email and phone number, and we want to require one or the other, but not both: We only want the email input to be…
Christian Smith
  • 7,851
  • 3
  • 15
  • 16
232
votes
40 answers

jQuery: what is the best way to restrict "number"-only input for textboxes? (allow decimal points)

What is the best way to restrict "number"-only input for textboxes? I am looking for something that allows decimal points. I see a lot of examples. But have yet to decide which one to use. Update from Praveen Jeganathan No more plugins, jQuery has…
wenbert
  • 5,113
  • 7
  • 46
  • 75
228
votes
33 answers

Regex Email validation

I use this @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" regexp to validate the email ([\w\.\-]+) - this is for the first-level domain (many letters and numbers, also point and hyphen) ([\w\-]+) - this is for second-level domain ((\.(\w){2,3})+) - and…
Sergey
  • 10,544
  • 23
  • 70
  • 110
221
votes
7 answers

Set Value of Input Using Javascript Function

I'm currently using a YUI gadget. I also do have a Javascript function to validate the output that comes from the div that YUI draws for me: Event.on("addGadgetUrl", "click", function(){ var url = Dom.get("gadget_url").value; /* line x…
Ali Taha Ali Mahboub
  • 2,751
  • 6
  • 23
  • 25
218
votes
15 answers

Do I really need to encode '&' as '&'?

I'm using an '&' symbol with HTML5 and UTF-8 in my site's . Google shows the ampersand fine on its SERPs, as do all the browsers in their titles. http://validator.w3.org is giving me this: & did not start a character reference. (& probably…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/html" class="post-tag grid--cell" title="show questions tagged 'html'" rel="tag">html</a> <a href="../../questions/tagged/utf-8" class="post-tag grid--cell" title="show questions tagged 'utf-8'" rel="tag">utf-8</a> <a href="../../questions/tagged/character-encoding" class="post-tag grid--cell" title="show questions tagged 'character-encoding'" rel="tag">character-encoding</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Aug 16 '10 at 13:09">asked Aug 16 '10 at 13:09</time> <a href="../../users/289666/haroldo" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/289666.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Haroldo" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/289666/haroldo" class="s-user-card--link">Haroldo</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">33,209</li> <li class="s-award-bling s-award-bling__gold" title="46 gold badges">46</li> <li class="s-award-bling s-award-bling__silver" title="123 silver badges">123</li> <li class="s-award-bling s-award-bling__bronze" title="164 bronze badges">164</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-4551783"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>217</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>18</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/4551783/no-grammar-constraints-dtd-or-xml-schema-detected-for-the-document" class="question-hyperlink">No grammar constraints (DTD or XML schema) detected for the document</a></h3> <div class="excerpt">I have this dtd : http://fast-code.sourceforge.net/template.dtd But when I include in an xml I get the warning : No grammar constraints (DTD or XML schema) detected for the document. The xml is : <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/xml" class="post-tag grid--cell" title="show questions tagged 'xml'" rel="tag">xml</a> <a href="../../questions/tagged/eclipse" class="post-tag grid--cell" title="show questions tagged 'eclipse'" rel="tag">eclipse</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/dtd" class="post-tag grid--cell" title="show questions tagged 'dtd'" rel="tag">dtd</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Dec 29 '10 at 05:47">asked Dec 29 '10 at 05:47</time> <a href="../../users/184730/fastcodejava" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/184730.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="fastcodejava" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/184730/fastcodejava" class="s-user-card--link">fastcodejava</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">35,219</li> <li class="s-award-bling s-award-bling__gold" title="24 gold badges">24</li> <li class="s-award-bling s-award-bling__silver" title="124 silver badges">124</li> <li class="s-award-bling s-award-bling__bronze" title="181 bronze badges">181</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-723587"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>213</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>5</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/723587/what-s-the-longest-possible-worldwide-phone-number-i-should-consider-in-sql-va" class="question-hyperlink">What's the longest possible worldwide phone number I should consider in SQL varchar(length) for phone</a></h3> <div class="excerpt">What's the longest possible worldwide phone number I should consider in SQL varchar(length) for phone. considerations: + for country code () for area code x + 6 numbers for Extension extension (so make it 8 {space}) spaces between groups (i.e. in…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/sql-server" class="post-tag grid--cell" title="show questions tagged 'sql-server'" rel="tag">sql-server</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/database-design" class="post-tag grid--cell" title="show questions tagged 'database-design'" rel="tag">database-design</a> <a href="../../questions/tagged/data-modeling" class="post-tag grid--cell" title="show questions tagged 'data-modeling'" rel="tag">data-modeling</a> <a href="../../questions/tagged/phone-number" class="post-tag grid--cell" title="show questions tagged 'phone-number'" rel="tag">phone-number</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Apr 06 '09 at 23:04">asked Apr 06 '09 at 23:04</time> <a href="../../users/75500/shimmy-weitzhandler" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/75500.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Shimmy Weitzhandler" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/75500/shimmy-weitzhandler" class="s-user-card--link">Shimmy Weitzhandler</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">92,920</li> <li class="s-award-bling s-award-bling__gold" title="119 gold badges">119</li> <li class="s-award-bling s-award-bling__silver" title="388 silver badges">388</li> <li class="s-award-bling s-award-bling__bronze" title="596 bronze badges">596</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-164979"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>204</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>31</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/164979/regex-for-matching-uk-postcodes" class="question-hyperlink">RegEx for matching UK Postcodes</a></h3> <div class="excerpt">I'm after a regex that will validate a full complex UK postcode only within an input string. All of the uncommon postcode forms must be covered as well as the usual. For instance: Matches CW3 9SS SE5 0EG SE50EG se5 0eg WC2H 7LT No Match aWC2H…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/regex" class="post-tag grid--cell" title="show questions tagged 'regex'" rel="tag">regex</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/regex-group" class="post-tag grid--cell" title="show questions tagged 'regex-group'" rel="tag">regex-group</a> <a href="../../questions/tagged/postal-code" class="post-tag grid--cell" title="show questions tagged 'postal-code'" rel="tag">postal-code</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Oct 02 '08 at 23:05">asked Oct 02 '08 at 23:05</time> <a href="../../users/5777/kieran-benton" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/5777.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Kieran Benton" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/5777/kieran-benton" class="s-user-card--link">Kieran Benton</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">8,177</li> <li class="s-award-bling s-award-bling__gold" title="11 gold badges">11</li> <li class="s-award-bling s-award-bling__silver" title="50 silver badges">50</li> <li class="s-award-bling s-award-bling__bronze" title="74 bronze badges">74</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-19166685"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>201</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>6</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/19166685/jquery-add-required-to-input-fields" class="question-hyperlink">jQuery add required to input fields</a></h3> <div class="excerpt">I have been searching ways to have jQuery automatically write required using html5 validation to my all of my input fields but I am having trouble telling it where to write it. I want to take this <input type="text" name="first_name" value=""…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/jquery" class="post-tag grid--cell" title="show questions tagged 'jquery'" rel="tag">jquery</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Oct 03 '13 at 18:38">asked Oct 03 '13 at 18:38</time> <a href="../../users/1276757/miura-shi" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1276757.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Miura-shi" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/1276757/miura-shi" class="s-user-card--link">Miura-shi</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">3,810</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="28 silver badges">28</li> <li class="s-award-bling s-award-bling__bronze" title="53 bronze badges">53</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-7341537"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>200</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>12</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/7341537/tool-to-generate-json-schema-from-json-data" class="question-hyperlink">Tool to generate JSON schema from JSON data</a></h3> <div class="excerpt">We have this json schema draft. I would like to get a sample of my JSON data and generate a skeleton for the JSON schema, that I can rework manually, adding things like description, required, etc, which can not be infered from the specific…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/json" class="post-tag grid--cell" title="show questions tagged 'json'" rel="tag">json</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/reflection" class="post-tag grid--cell" title="show questions tagged 'reflection'" rel="tag">reflection</a> <a href="../../questions/tagged/jsonschema" class="post-tag grid--cell" title="show questions tagged 'jsonschema'" rel="tag">jsonschema</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Sep 07 '11 at 23:14">asked Sep 07 '11 at 23:14</time> <a href="../../users/647991/bluefast" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/647991.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="blueFast" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/647991/bluefast" class="s-user-card--link">blueFast</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">33,335</li> <li class="s-award-bling s-award-bling__gold" title="48 gold badges">48</li> <li class="s-award-bling s-award-bling__silver" title="165 silver badges">165</li> <li class="s-award-bling s-award-bling__bronze" title="292 bronze badges">292</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-4870961"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>199</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>3</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/4870961/validate-uniqueness-of-multiple-columns" class="question-hyperlink">Validate uniqueness of multiple columns</a></h3> <div class="excerpt">Is there a rails-way way to validate that an actual record is unique and not just a column? For example, a friendship model / table should not be able to have multiple identical records like: user_id: 10 | friend_id: 20 user_id: 10 | friend_id: 20 </div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/ruby-on-rails" class="post-tag grid--cell" title="show questions tagged 'ruby-on-rails'" rel="tag">ruby-on-rails</a> <a href="../../questions/tagged/ruby-on-rails-3" class="post-tag grid--cell" title="show questions tagged 'ruby-on-rails-3'" rel="tag">ruby-on-rails-3</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/activerecord" class="post-tag grid--cell" title="show questions tagged 'activerecord'" rel="tag">activerecord</a> <a href="../../questions/tagged/rails-activerecord" class="post-tag grid--cell" title="show questions tagged 'rails-activerecord'" rel="tag">rails-activerecord</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Feb 02 '11 at 05:05">asked Feb 02 '11 at 05:05</time> <a href="../../users/132877/re5et" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/132877.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="re5et" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/132877/re5et" class="s-user-card--link">re5et</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">4,145</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="21 silver badges">21</li> <li class="s-award-bling s-award-bling__bronze" title="24 bronze badges">24</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-18419428"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>197</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>8</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/18419428/what-is-the-minimum-valid-json" class="question-hyperlink">What is the minimum valid JSON?</a></h3> <div class="excerpt">I've carefully read the JSON description http://json.org/ but I'm not sure I know the answer to the simple question. What strings are the minimum possible valid JSON? "string" is the string valid JSON? 42 is the simple number valid JSON? true is…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/javascript" class="post-tag grid--cell" title="show questions tagged 'javascript'" rel="tag">javascript</a> <a href="../../questions/tagged/json" class="post-tag grid--cell" title="show questions tagged 'json'" rel="tag">json</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Aug 24 '13 at 14:08">asked Aug 24 '13 at 14:08</time> <a href="../../users/230214/bessarabov" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/230214.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="bessarabov" onerror="onImageLoadingError(this);" /> </a> <div class="s-user-card--info"> <a href="../../users/230214/bessarabov" class="s-user-card--link">bessarabov</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">9,163</li> <li class="s-award-bling s-award-bling__gold" title="7 gold badges">7</li> <li class="s-award-bling s-award-bling__silver" title="30 silver badges">30</li> <li class="s-award-bling s-award-bling__bronze" title="51 bronze badges">51</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="s-pagination pager fr"> <a class="s-pagination--item" href="../../questions/tagged/validation_page=2" rel="prev" title="Go to page 2">Prev </a> <a class="s-pagination--item" href="../../questions/tagged/validation_page=1" rel="" title="Go to page 1">1</a> <a class="s-pagination--item" href="../../questions/tagged/validation_page=2" rel="" title="Go to page 2">2</a> <div class="s-pagination--item is-selected">3</div> <div class="s-pagination--item s-pagination--item__clear">…</div> <a class="s-pagination--item" href="../../questions/tagged/validation_page=99" rel="" title="Go to page 99">99</a> <a class="s-pagination--item" href="../../questions/tagged/validation_page=100" rel="" title="Go to page 100">100</a> <a class="s-pagination--item" href="../../questions/tagged/validation_page=4" rel="next" title="Go to page 4"> Next</a> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script> /* replace <time class="fromnow" /> with human delta between `datetime` attr and now */ document.addEventListener('DOMContentLoaded', function(){ var time_elements = document.querySelectorAll("time.fromnow"); for (var i=0; i<time_elements.length; i++) { time_elements[i].innerHTML = moment(time_elements[i].getAttribute("datetime")).fromNow(); } }); </script> </body> </html>