compile SUBROUTINE PHONE_FORMAT( charstr CONV, charstr ANS, charstr BRANCH, charstr RETURN_DATA)
*
*   PHONE_FORMAT is an example of a developer's custom prompt formatting
*   routine using the square brackets call.
*
*   It should be placed in square brackets, like this:
*
*                   [PHONE_FORMAT]
*
* This subroutine should be used as the first and only "Input Validation" in
* a window prompt.  Placed in "Output Format", it properly formats any
* reasonable string of numbers into a consistent US telephone number format.
*
* mtr 5-29-01  Changed @upper.case to @lower.case conversion
* mtr 3-18-02  Added '.' as a valid delimiter.
!
begin condition
pre:
post:
end condition

*  Subroutine declarations

$insert msg_equates

declare function msg

*  Local Equates
*  The STATUS() variable is used to indicated the error condition of the
*  pattern. They are:
EQU VALID$         TO 0    ;* Successful
EQU INVALID_MSG$   TO 1    ;* Bad Data       -   Print error message window
EQU INVALID_CONV$  TO 2    ;* Bad Conversion -          "         "
EQU INVALID_NOMSG$ TO 3    ;* Bad but do not print the error message window

EQU THREEDGRAY$    TO 192

*  Begin Conversion
*
  RETURN_DATA = ""
  IF ANS NE "" THEN
     TEL = ANS
     ANS = ""
     STATUS() = VALID$
  
     *DFLT_AREA_CODE = ""
     * PHONE_FORMAT can support a default area code. To assign a default
     * simply set the variable DFLT_AREA_CODE.  In this example it is set to
     * null.
     *CONVERT " -()" TO "" IN DFLT_AREA_CODE
     *IF NUM( DFLT_AREA_CODE ) ELSE DFLT_AREA_CODE = ""
  
     CONVERT " -()." TO "" IN TEL
     * mtr 
     CONVERT @LOWER.CASE TO @UPPER.CASE IN TEL
     CONVERT "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "2223334445556667Q77888999Z" IN TEL
  
     IF NUM( TEL ) THEN
         LENGTH = LEN( TEL )
         * Case statement to validate all possible types of phone numbers. If
         * a new format is required simply add another case.
         * The fall-through (CASE 1) traps invalid conversions.
         BEGIN CASE
           CASE LENGTH = 10
              IF CONV EQ "OCONV" THEN
                RETURN_DATA = FMT( TEL, "L(###) ###-####")
              END ELSE
                RETURN_DATA = TEL
              END
           CASE LENGTH EQ 7
              IF CONV EQ "OCONV" THEN
                RETURN_DATA = FMT( TEL, "L###-####")
              END ELSE
                RETURN_DATA = TEL
              END
           CASE 1
              IF CONV = "ICONV" THEN
                  gosub DisplayError
              END
              STATUS() = INVALID_NOMSG$
         END CASE
     END ELSE
         IF CONV = "ICONV" THEN
             gosub DisplayError
         END
         STATUS() = INVALID_NOMSG$
     END
  END
  RETURN
*}

DisplayError:              
    msgrec            = ""
    msgrec<MCAPTION$> = "Data Validation Error"
    msgrec<MTEXT$>    = TEL : " is not a valid phone number. Please enter a seven or ten digit number in any format."
    msgrec<MBKCOLOR$> = THREEDGRAY$:@VM:THREEDGRAY$:@VM:THREEDGRAY$
    msgrec<MJUST$>    = 'L'
    result = msg( "", msgrec)
return

* Source Date: 11:16:17  21 OCT 1991  Build ID: AREV*2.12.5  Level: 2.12
