Here are some descriptions of what is done in the above script:


21.1. Retrieving Form Data and Removing Leading and Trailing Whitespaces

The form data entered by the user is stored in five WML variables: username, password, email, name and birthday. Before validation can be done, we have to retrieve the value of these WML variables. Any leading and trailing whitespaces should be removed since we do not want the user name, the password, etc, to be a few space characters:


  var form_username = String.trim(WMLBrowser.getVar("username"));
  var form_password = String.trim(WMLBrowser.getVar("password"));
  var form_email = String.trim(WMLBrowser.getVar("email"));
  var form_name = String.trim(WMLBrowser.getVar("name"));
  var form_birthday = String.trim(WMLBrowser.getVar("birthday"));


21.2. Checking Whether All Required Fields Has been Filled

Then we use the following WMLScript code to check whether the user has filled in all the required fields. The WMLScript code is very straightforward. If any of the variables contains an empty string, we will assign an error message to the WML variable errorMsg, refresh the WML browser and quit the validate() function:


  if (""==form_username){
    WMLBrowser.setVar("errorMsg", "The User Name field must not be empty.");
    WMLBrowser.refresh();
    return;
  }

  if (""==form_password){
    WMLBrowser.setVar("errorMsg", "The Password field must not be empty.");
    WMLBrowser.refresh();
    return;
  }

  if (""==form_email){
    WMLBrowser.setVar("errorMsg", "The Email field must not be empty.");
    WMLBrowser.refresh();
    return;
  }


The following screenshots show the error message that you will see if you do not fill in the username field:



Sony Ericsson T68i


Nokia Mobile Browser 4.0


21.3. Checking the Length of Password

Next, the length() function of the String standard library is used to check the number of characters contained in the password variable. If it is fewer than eight, the WML browser will display an error message to notify the user of the problem:


  if (String.length(form_password) < 8){
    WMLBrowser.setVar("errorMsg", "The password must contain at least 8 characters since a short password is less secure.");
    WMLBrowser.refresh();
    return;
  }


The following screenshots show the error message that you will see if you enter a password that contains fewer than eight characters:






Sony Ericsson T68i


Nokia Mobile Browser 4.0


Previous Page Page 67 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page