EzDevInfo.com

validation interview questions

Top validation frequently asked interview questions

What's the best way to validate an XML file against an XSD file?

I'm generating xml files that need to conform to an xsd that was given to me. What's the best way to do this?


Source: (StackOverflow)

An invalid form control with name='' is not focusable

I have an acute problem on my website. In Google Chrome some customers are not able to proceed to my payment page. When trying to submit a form I get this error:

An invalid form control with name='' is not focusable.

This is from the JavaScript console.

I read that the problem could be due to hidden fields having the required attribute. Now the problem is that we are using .net webforms required field validators, and not the html5 required attribute.

It seems random who gets this error. Is there anyone who knows a solution for this?


Source: (StackOverflow)

Advertisements

jQuery validate: How to add a rule for regular expression validation?

I am using the jQuery validation plugin. Great stuff! I want to migrate my existing ASP.NET solution to use jQuery instead of the ASP.NET validators. I am missing a replacement for the regular expression validator. I want to be able to do something like this:

$("Textbox").rules("add", { regularExpression: "^[a-zA-Z'.\s]{1,40}$" })

How do I add a custom rule to achieve this?


Source: (StackOverflow)

How do I remove javascript validation from my eclipse project?

I am using eclipse on my project and while messing around with my eclipse settings, I turned on Javascript support. Now eclipse complains that JQuery library has errors in it and is not letting me compile the project. Does anyone know how to turn javascript validation off?


Source: (StackOverflow)

Which characters make a URL invalid?

I am writing BBCode for my own forum (based on PHP). How do you find out if it is an invalid URL provided in the the [url] tag? Which characters make a URL invalid?

To extend my main question, are these valid URLs?—

  • example.com/file[/].html
  • http://example.com/file[/].html

Source: (StackOverflow)

Check if inputs are empty using jQuery

I have a form that I would like all fields to be filled in. If a field is clicked into and then not filled out, I would like to display a red background.

Here is my code:

$('#apply-form input').blur(function () {
  if ($('input:text').is(":empty")) {
    $(this).parents('p').addClass('warning');
  }
});

It applies the warning class regardless of the field being filled in or not.

What am I doing wrong?


Source: (StackOverflow)

Validate email address in JavaScript?

How can an email address be validated in JavaScript?


Source: (StackOverflow)

Validate decimal numbers in JavaScript - IsNumeric()

What's the cleanest, most effective way to validate decimal numbers in JavaScript?

Bonus points for:

  1. Clarity. Solution should be clean and simple.
  2. Cross-platform.

Test cases:

 01. IsNumeric('-1') => true
 02. IsNumeric('-1.5') => true
 03. IsNumeric('0') => true
 04. IsNumeric('0.42') => true
 05. IsNumeric('.42') => true
 06. IsNumeric('99,999') => false
 07. IsNumeric('0x89f') => false
 08. IsNumeric('#abcdef')=> false
 09. IsNumeric('1.2.3') => false
 10. IsNumeric('') => false
 11. IsNumeric('blah') => false

Source: (StackOverflow)

A potentially dangerous Request.Form value was detected from the client

Every time a user posts something containing < or > in a page in my web application, I get this exception thrown.

I don't want to go into the discussion about the smartness of throwing an exception or crashing an entire web application because somebody entered a character in a text box, but I am looking for an elegant way to handle this.

Trapping the exception and showing An error has occured please go back and re-type your entire form again, but this time please do not use < doesn't seem professional enough to me.

Disabling post validation (validateRequest="false") will definitely avoid this error, but it will leave the page vulnerable to a number of attacks.

Ideally: When a post back occurs containing HTML restricted characters, that posted value in the Form collection will be automatically HTML encoded. So the .Text property of my text-box will be something & lt; html & gt;

Is there a way I can do this from a handler?


Source: (StackOverflow)

How does the SQL injection from the "Bobby Tables" XKCD comic work?

Just looking at:

XKCD Strip (Source: https://xkcd.com/327/)

What does this SQL do:

Robert'); DROP TABLE STUDENTS; --

I know both ' and -- are for comments, but doesn't the word DROP get commented as well since it is part of the same line?


Source: (StackOverflow)

How to allow only numeric (0-9) in HTML inputbox using jQuery?

I am creating a web page where I have an input text field in which I want to allow only numeric characters like (0,1,2,3,4,5...9) 0-9.

How can I do this using jQuery?


Source: (StackOverflow)

A comprehensive regex for phone number validation

I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it would handle international formats, but it must handle US formats, including the following:

  • 1-234-567-8901
  • 1-234-567-8901 x1234
  • 1-234-567-8901 ext1234
  • 1 (234) 567-8901
  • 1.234.567.8901
  • 1/234/567/8901
  • 12345678901

I'll answer with my current attempt, but I'm hoping somebody has something better and/or more elegant.


Source: (StackOverflow)

What is the maximum length of a valid email address?

What is the maximum length of a valid email address? Is it defined by any standard?


Source: (StackOverflow)

Is there a (built-in) way in JavaScript to check if a string is a valid number?

I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric() function?


Source: (StackOverflow)

Disable validation of HTML5 form elements

In my forms, I'd like to use the new HTML5 form types, for example <input type="url" /> (more info about the types here).

The problem is that Chrome wants to be super helpful and validate these elements for me, except that it sucks at it. If it fails the built-in validation, there's no message or indication other than the element getting focus. I prefill URL elements with "http://", and so my own custom validation just treats those values as empty strings, however Chrome rejects that. If I could change its validation rules, that would work too.

I know I could just revert back to using type="text" but I want the nice enhancements using these new types offers (eg: it automatically switches to a custom keyboard layout on mobile devices):

So, is there a way to switch off or customise the automatic validation?


Source: (StackOverflow)