Adding Validation for Witness Phone Field

This validation ensures that the value specified for the Witness Phone field is in a valid format.

Procedure

  1. In the Witness Information pane, click the Witness Phone field.
  2. Click the Validations tab on the control’s Properties view.
  3. Click the Add New Validation button.

    The Define Validation dialog opens.

  4. In the Name field type the following: phone_number_syntax
  5. Select the On Value Change radio button.
  6. Type the following JavaScript code in the Script text area:
    //Retrieve the phone value
    var phone = this.getValue();
    if(phone != null && phone != ""){
     //verify it is in the format 888-888-8888
     var strippedPhone = '';
        var strippedPhone = '';
        for(var i=0; i<phone.length; i++){
              var c = phone.charAt(i);
              var isNonDigitChar = isNaN(parseInt(c));
              if(!isNonDigitChar){ // check if c is a digit
                strippedPhone += c;
              }
        }
        strippedPhone.length == 10;
    } else{
        true;
    }
  7. Type the following text in the Message area:
    Phone number must be of the form (888) 888-8888.
  8. Click Finish.