MS Exam 70-536 - How can you constrain the input before you write any code?
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 appl开发者_高级运维ication 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?
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).
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.
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?
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.
精彩评论