Validating fields with the web UI framework

You can validate fields against certain standards, using the default validation system or your own validation system.

About this task

The Web UI Framework provides validation for the following three types of information in the en_US locale:
  • E-mail address (using the international accepted standard)
  • Telephone number format (locale-specific)
  • Credit card number (using the Luhn algorithm)

To validate items, do the following:


  1. Register the field attributes that you will be using for validation by implementing the registerFieldAttributes(validationType, attribute) function, using the following arguments:
    • validationType (required)

      Validation type. By default, the application includes validation types for e-mail address, telephone number format, and credit card number.

    • attribute

      XML attributes for validations. An attribute can be registered for multiple validation types.

      Use this function to implement customized validators that you want to plug in to the application.

  2. Implement the registerValidators(validationType, validator) function, using the following arguments:
    • validationType (required)

      Validation type.

    • validator (required)

      Validator function for validation type.


The following is an example of how to add validation for a last name:

sc.plat.ValidateUtils.registerValidator('LastName', function (value){
    if (value == null || value.length<2) {
        return {status: 2,message: "Last name needs at least two characters" };
    return {status: 1};