validation interview questions
Top validation frequently asked interview questions
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)
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)
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)
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)
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)
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)
What's the cleanest, most effective way to validate decimal numbers in JavaScript?
Bonus points for:
- Clarity. Solution should be clean and simple.
- 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)
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)
Just looking at:
(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)
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)
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)
I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric() function?
Source: (StackOverflow)
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)