views:

153

answers:

4

Hello! In MS Exam 70-536 .Net Foundation, Chapter 3 "Searching, Modifying, and Encoding Text" in Case Scenario 1

Your organization, Northwind Traders, is creating a Web-based application to allow customers to enter their own contact information into your database. As a new employee, you are assigned a simple task: create the front-end interface and prepare the user input to be stored in a database...

there is a question:

How can you constrain the input before you write any code?

I thought it's maybe a in-mind design of regex pattern but it will not really constrain the input, will it? I am not so good in psychokinesis yet!

Or maybe the is some other way?

Thanks for your time!

+7  A: 

What sort of input is it talking about?

TextBox (at least in Windows Forms) has a bunch of properties that can constrain input without writing any code. For example, MaxLength will stop the user from entering a string past a certain length. CharacterCasing will force the text to upper or lower case.

Similarly, controls such as MaskedTextBox, DateTimePicker or NumericUpDown allow input without allowing free-text input, so the user might be constrained to a certain type (DateTime or Decimal).

Matt Hamilton
You could even argue for ComboBox as a way of constraining the user to select from a pre-defined set of strings.
itowlson
Yeah that's very true! Forgot about that one! RadioButtons and CheckBoxes too, really. Not so much "text" but definitely "input".
Matt Hamilton
down vote, 70-536 is not about Windows Forms.
Nicolas Dorier
question updated, its about web interface, and using specific ui control and it's properties also seems to be reasonable but not in this exam. thanks!
Max Gontar
A lot of what I've written applies to web interfaces too. CharacterCasing isn't there but MaxLength is. Also there are calendar controls etc for ASP.NET.
Matt Hamilton
@Nicolas I appreciate you leaving a comment with your down-vote. I tried to be platform-agnostic with my answer, using winforms only as an example.
Matt Hamilton
Hi Nick, you are right the Exam is not about WinForms but the scenarios at the end of each chapter often touch upon WPF and WF related scenarios. So I upped this answer as the scenarios only care about making sure you that the exam taker is practising the subject is as many different relevant contexts as possible. That's all they care about strictly speaking you are correct but the answer is still fair.
IbrarMumtaz
+1  A: 

The two things that come to mind immediately are either constraining the character set, or adding check constraints to the DB.

The question is vague, and the answer to that might be dependent upon where validation needed to happen, what technologies are used, and frankly what the definition of 'code' is. For instance, does creating a custom type that embeds the constraints qualify as "code"? Does HTML count if it's a web-app? Client-side Javascript?

kyoryu
set encoding may be reasonable since it's also a part of chapter 3 but how it could limit the input?
Max Gontar
If there's a way to limit the character set to ASCII, you won't get double-byte characters. It's a bit of a stretch, frankly, but it does constrain the inputs to some extent. I'd be more tempted to look into what constraints can be put on controls in the HTML, but I don't know if that qualifies as "code."
kyoryu
A lot of questions in the 70-536 book are vague. It's far out the worst technical book I've ever read (and I read a lot).
Steven
A: 

I've noticed there are answers in the end of the book :)

Answer: You can use separate ASP.NET RegularExpressionValidator controls to restrict the input for each of the three boxes. For the company name validator, set the ValidationExpression property to “[a-zA-Z'-´\s]{1,40}”. For the contact name validator, you can use the regular expression, “[a-zA-Z'-´\s]{1,30}”. Finally, for the phone number validator, you can use ASP.NET’s built-in regular expression, “(((\d{3}) ?)|(\d{3}-))?\d{3}-\d{4}”.

Still I think it's not correct, knowledge requirements are

To complete the lessons in this chapter, you should be familiar with Microsoft Visual Basic or C# and be comfortable with the following tasks:
■ Create a console application in Microsoft Visual Studio using Visual Basic or C#.
■ Add references to system class libraries to a project.
■ Create text files.

Max Gontar
+1  A: 

Somewheres towards the middle of the book you will find some attributes called StringInputValidators ........ here look below ....

[ConfigurationProperty("lastUser", DefaultValue = "User", IsRequired = true)]
[StringValidator(InvalidCharacters  = ""!@#$%^&")] // and etc
public string LastUser
{   // get and set accessor code logic in here. }

It should be pretty obvious what this does, this is one way of limiting what text an be applied to a string property. It's the "code" way of ofc but I don't know how to do this via the VS UIs if there is such a way of applying atttributes like this. Nonetheless it partially answers your question.

IbrarMumtaz
Its great to learn something new! Thanks!
Max Gontar