Constraints

apps can tailor the behavior of text boxes and text fields, and possibly the keyboard mappings of the device, by using the constants covered in this section. apps can use one constraint per text box or text field.

app Developers

Recommend: Java graphics bulb2_icon.gif Use constraints. The implementation may be able to use them to limit the user's input and decrease user error.

The ANY Constraint

The ANY constraint permits the user to enter any character on the device. The characters available are device-dependent.

MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif Your device must support, at a minimum, the characters in the ITU-T keypad (0-9, *, #). If your device does not have a keypad, give the user some other method of entering these characters. (For example, users of Palm OS devices could enter these characters using graffiti.)

The NUMERIC Constraint

The NUMERIC constraint limits the user to providing integer values, with an optional minus sign (-) to indicate that the integer is negative. Screenshot shows a text field with a numeric constraint.

Screenshot Text Field with a NUMERIC Constraint

Java graphics 06fig02.gif


MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif Determine the mechanism for changing the sign of the value in the NUMERIC text box or field. For example, the MIDP Reference Implementation uses the star key (*) to toggle the minus sign.

Strongly Recommend: Java graphics bulb1_icon.gif You must ensure that the text box or text field is empty, or its value is an integer. You must not permit the user to enter any letters or other characters into a text box or field with a NUMERIC constraint.

app Developers

Strongly Recommend: Java graphics bulb1_icon.gif When you assign a maximum size (maximum number of characters) to a text box with a numeric constraint, remember to allow space for the minus sign if the user might enter a negative number. Users cannot enter negative numbers into text boxes that have a maximum size of one.

The DECIMAL Constraint

The DECIMAL constraint limits the user to providing only numeric values, with optional decimal fractions. For example, the following are legal values: -123, 0.123, and .5. Screenshot shows a text field with a DECIMAL constraint.

Screenshot Text Field with a DECIMAL Constraint

Java graphics 06fig03.gif


MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif You must ensure that a text box or field is either empty or that its value is a real number. You must not permit the user to enter any illegal characters into a text box or field with a DECIMAL constraint.

Strongly Recommend: Java graphics bulb1_icon.gif If the real number has a fractional part, it is separated from the integer part by a separator character that can vary depending on your implementation. The displayed character is typically a period (.) or comma (,) or some other character depending on the locale. Regardless of the character shown to the user, the actual value provided to the app must use the period (.) as the separator.

app Developers

Strongly Recommend: Java graphics bulb1_icon.gif Your MIDlet is responsible for parsing the string value of the text box into a numeric value suitable for computation.

Strongly Recommend: Java graphics bulb1_icon.gif When you assign a maximum size to a text box with a DECIMAL constraint, remember to allow space for the sign and the fraction separator.

The PHONENUMBER Constraint

The PHONENUMBER constraint hints to the MIDP implementor that the user will be entering a phone number.

MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif Determine whether the PHONENUMBER constraint limits the characters that the user can enter, the formatting of the value entered, or both.

Consider: Present the phone number (the contents of the text field) in a way that is readable by users. For example, although the content of the text field might be 4085551212, you could display it more readably as 408.555.1212 or (408) 555-1212.

Strongly Recommend: Java graphics bulb1_icon.gif If you present the phone number to the user with additional characters, such as spaces, do not provide those extra characters to the app.

The EMAIL Constraint

The EMAIL constraint hints to the MIDP implementor that the user will be entering an email address.

MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif Determine whether the EMAIL constraint limits the characters that the user can enter. For example, you might decrease user error by not allowing users to enter characters that are commonly invalid, such as slash (/), comma (,), colon (:), or semicolon (;).

Strongly Recommend: Java graphics bulb1_icon.gif Do not capitalize the characters in a text box with an EMAIL constraint.

app Developers

Strongly Recommend: Java graphics bulb1_icon.gif Have your MIDlet check the contents of the text field if it requires a properly formatted email address. The app must validate the user's input because the MIDP specification does not require the device to do so.

The URL Constraint

The URL constraint hints to the MIDP implementor that the user will be entering a URL.

MIDP Implementors

Strongly Recommend: Java graphics bulb1_icon.gif Determine whether the URL constraint limits the characters that the user can enter. For example, the valid characters in a domain name are letters, numbers and hyphens (-).

Strongly Recommend: Java graphics bulb1_icon.gif Do not capitalize the characters in a text box with a URL constraint.

app Developers

Strongly Recommend: Java graphics bulb1_icon.gif Have your MIDlet check the contents of the text field if it requires a properly formed URL. The app must validate the user's input because the MIDP specification does not require the device to do so.

Screenshot


   
Comments