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:

67160 questions
268
votes
37 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
  • 11,548
  • 24
  • 76
  • 113
264
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
  • 3,271
  • 6
  • 26
  • 25
261
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
  • 8,102
  • 5
  • 32
  • 28
259
votes
6 answers

What's the longest possible worldwide phone number I should consider in SQL varchar(length) for phone

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…
258
votes
17 answers

Check whether an input string contains a number in javascript

My end goal is to validate an input field. The input may be either alphabetic or numeric.
Udara S.S Liyanage
  • 6,189
  • 9
  • 33
  • 34
251
votes
3 answers

What HTTP status code should be used for wrong input

What is optimal HTTP response Code when not reporting 200 (everything OK) but error in input? Like, you submit some data to server, and it will response that your data is wrong using 500 looks more like Server Issue using 200 with warning/error…
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
250
votes
12 answers

Tool to generate JSON schema from JSON data

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…
blueFast
  • 41,341
  • 63
  • 198
  • 344
250
votes
6 answers

jQuery add required to input fields

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
Miura-shi
  • 4,409
  • 5
  • 36
  • 55
246
votes
19 answers

What is the best Java email address validation method?

What are the good email address validation libraries for Java? Are there any alternatives to commons validator?
jon077
  • 10,303
  • 11
  • 39
  • 37
241
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,685
  • 2
  • 17
  • 8
239
votes
33 answers

RegEx for matching UK Postcodes

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…
Kieran Benton
  • 8,739
  • 12
  • 53
  • 77
238
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
  • 8,089
  • 3
  • 19
  • 18
237
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" /> </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">36,607</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="127 silver badges">127</li> <li class="s-award-bling s-award-bling__bronze" title="169 bronze badges">169</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-891696"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>236</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>40</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/891696/jquery-what-is-the-best-way-to-restrict-number-only-input-for-textboxes-allow-" class="question-hyperlink">jQuery: what is the best way to restrict "number"-only input for textboxes? (allow decimal points)</a></h3> <div class="excerpt">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…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <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> <a href="../../questions/tagged/isnumeric" class="post-tag grid--cell" title="show questions tagged 'isnumeric'" rel="tag">isnumeric</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked May 21 '09 at 07:04">asked May 21 '09 at 07:04</time> <a href="../../users/66767/wenbert" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/66767.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="wenbert" /> </a> <div class="s-user-card--info"> <a href="../../users/66767/wenbert" class="s-user-card--link">wenbert</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">5,263</li> <li class="s-award-bling s-award-bling__gold" title="8 gold badges">8</li> <li class="s-award-bling s-award-bling__silver" title="48 silver badges">48</li> <li class="s-award-bling s-award-bling__bronze" title="77 bronze badges">77</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-62059408"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>235</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>10</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/62059408/reactjs-and-typescript-refers-to-a-value-but-is-being-used-as-a-type-here-ts27" class="question-hyperlink">ReactJS and Typescript : refers to a value, but is being used as a type here (TS2749)</a></h3> <div class="excerpt">I'm coding a ReactJS class with Typescript and Material-ui, in a .tsx file. In one of my custom components, I want to create a reference to one of the components that I use in my custom component. export class MyTextField extends…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/reactjs" class="post-tag grid--cell" title="show questions tagged 'reactjs'" rel="tag">reactjs</a> <a href="../../questions/tagged/typescript" class="post-tag grid--cell" title="show questions tagged 'typescript'" rel="tag">typescript</a> <a href="../../questions/tagged/validation" class="post-tag grid--cell" title="show questions tagged 'validation'" rel="tag">validation</a> <a href="../../questions/tagged/material-ui" class="post-tag grid--cell" title="show questions tagged 'material-ui'" rel="tag">material-ui</a> <a href="../../questions/tagged/tsx" class="post-tag grid--cell" title="show questions tagged 'tsx'" rel="tag">tsx</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked May 28 '20 at 07:39">asked May 28 '20 at 07:39</time> <a href="../../users/13165246/answerrer" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/13165246.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Answerrer" /> </a> <div class="s-user-card--info"> <a href="../../users/13165246/answerrer" class="s-user-card--link">Answerrer</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">2,803</li> <li class="s-award-bling s-award-bling__gold" title="4 gold badges">4</li> <li class="s-award-bling s-award-bling__silver" title="8 silver badges">8</li> <li class="s-award-bling s-award-bling__bronze" title="18 bronze badges">18</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 src="../../static/js/fromnow.js"></script> </body> </html>