Constraints





6.1 Constraints

Applications 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. Applications can use one constraint per text box or text field.

Application Developers

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

6.1.1 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: 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.)

6.1.2 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. Figure shows a text field with a numeric constraint.

Figure. Text Field with a NUMERIC Constraint

graphics/06fig02.gif

MIDP Implementors

Strongly Recommend: 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: 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.

Application Developers

Strongly Recommend: 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.

6.1.3 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. Figure shows a text field with a DECIMAL constraint.

Figure. Text Field with a DECIMAL Constraint

graphics/06fig03.gif

MIDP Implementors

Strongly Recommend: 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: 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 application must use the period (.) as the separator.

Application Developers

Strongly Recommend: 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: 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.

6.1.4 The PHONENUMBER Constraint

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

MIDP Implementors

Strongly Recommend: 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: 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 application.

6.1.5 The EMAIL Constraint

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

MIDP Implementors

Strongly Recommend: 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: graphics/bulb1_icon.gif Do not capitalize the characters in a text box with an EMAIL constraint.

Application Developers

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

6.1.6 The URL Constraint

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

MIDP Implementors

Strongly Recommend: 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: graphics/bulb1_icon.gif Do not capitalize the characters in a text box with a URL constraint.

Application Developers

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


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows