Error+Checking+Integer+Input

For the Integer Clusters, these are the agreed upon standards for validating input in an integer input box as approved by Trish Steele (Story board lead) – March 2010.

NOTE: (as of November, 2010) A tool has been developed that will turn any regular textfield into an "Integer Input box", which can automatically handle all of the error checking below. Currently, the feedback is not identical to that listed on this page. (This can be negotiated). To check out this tool and its details, visit the ubError Checking - Integer Input box page

Ensure input is valid and provide indicated feedback before dealing with the activity specific feedback.

For input do not accept the following: Letters, symbols and decimal numbers Thus, things like ‘k’ ‘2.0’ and 2/1 do not need to have feedback attached to it.

**Timing of feedback:** The programmer retains the right to decide when the feedback is best given. For some activities, it might make sense for some feedback to appear immediately upon entry. Generally, we probably want to give students time to think about what they are entering and possibly change their mind, so feedback should happen after an "Enter" key or "Check" Button is hit. Invalid entries should generally not count as an error when keeping track of number of attempts.


 * ** Invalid input ** || ** Feedback ** || ** Action ** || ** Suggestions for timing of feedback ** ||
 * 2- or 2+ || // The <“+” /“-“ // > sign is written before the number, re-enter starting with the sign. || Highlight the input box

Make sure +/- signs are in quotes throughout feedback. || As soon as the sign part of the number is entered || +-2, --2, ++2, -+2 || An integer has only one sign. Enter an integer. || Highlight input box || After the second sign is entered || This is a matter of standard format, not an error. || After the first non-zero digit is entered || 6++ 2-+4  2 - 4 || Enter a valid integer. || Highlight input box ||  ||
 * + or - || Enter a number after the  sign.// || Place cursor in textbox after the sign || After submitted ||
 * +0 or -0 || Zero is neither positive nor negative. Try again. || Rest the focus, require the user to enter a different value. || As soon as the zero is entered ||
 * Double signs for example:
 * 09, -03, +007 || Leading zeros are not necessary. || Action should proceed as if they entered 9, -3, or 7. (Replace values where appropriate.)
 * Anything else strange,
 * +2 versus 2 ||  || Treat as if they were the same unless specifically instructed otherwise in the storyboard. ||   ||


 * Note: For those of us who used parseInt to convert to a number, leading white space and trailing non-numeric characters are ignored. parseInt(2+-) will return 2 and not NaN
 * use isNaN rather than parseInt to check for non-numeric input

if (isNaN(yardMarker_txt.text)) {

Selection.setFocus("yardMarker_txt"); Selection.setSelection(0,yardMarker_txt.length);

//only the sign has been entered// //if (((yardMarker_txt.text.substring(0, 1) == "+") || (yardMarker_txt.text.substring(0, 1) == "-")) && (yardMarker_txt.length == 1)) {// //feedback_txt.htmlText = "Enter a number after the \"" + yardMarker_txt.text.substring(0, 1) + "\" sign.";//

double signs have been entered } else if (((yardMarker_txt.text.substring(0, 2) == "++") || (yardMarker_txt.text.substring(0, 2) == "+-") || (yardMarker_txt.text.substring(0, 2) == "--") || (yardMarker_txt.text.substring(0, 2) == "-+")) && (!isNaN(yardMarker_txt.text.substring(2, yardMarker_txt.text.length)))) { feedback_txt.htmlText = "An integer has only one sign. Enter an integer.";

//sign has been entered at the end// //} else if (((yardMarker_txt.text.substring(yardMarker_txt.length - 1, yardMarker_txt.length) == "+") || (yardMarker_txt.text.substring(yardMarker_txt.length - 1, yardMarker_txt.length) == "-")) && (yardMarker_txt.text.substring(0, 1) != "+") && (yardMarker_txt.text.substring(0, 1) != "-") && (!isNaN(yardMarker_txt.text.substring(0, yardMarker_txt.text.length - 1)))) {// //feedback_txt.htmlText = "The \"" + yardMarker_txt.text.substring(yardMarker_txt.length - 1, yardMarker_txt.length) + "\" sign is written before the number, re-enter starting with the sign.";//

everything else in invalid } else { feedback_txt.htmlText = "Enter a valid integer."; } }