IVR Input Validation

Hello,

I am interested if anyone knows how to create an IVR however to use a set of rules to validate the READ/INPUT.

eg: I want the customer to input a 10digit number, however if the customer enters 7x digits and then hash it will accept it.
I want to count the digits and if it is not 10 then play some audio and start the IVR again.

Anyone know of this code ability?

Thanks.

I had to do something similar in an application I wrote to collect phone numbers.

I wanted to have the user put in a North American telephone number. Just the 10 digit area code-exchange-extension combination.

However, experience has taught me that callers who are asked to enter their ten digit number, (as in 617-555-1234), often start the number with 1. (As in 1-617-555-1234.) It’s just habit, as that’s how they would dial the number if they were calling that phone.

I wanted to be able to tell if it were a 10 digit number, an 11 digit number, something greater than 11, or less than 10 digits.

Here is the code I used.

First: In another context, I collect the digits.

exten => s,1,Read(digits,greeting,s,3,5)

Playing a soundfile called ‘greeting’, the caller is asked three times to enter a phone number. They are given 5 seconds to begin to enter their number.

Second: I check the digits length with this code, and send the callers to different contexts depending on it’s length.

exten => s,1,GotoIf($[${LEN(${digits})} = 0]?sorry,s,1)
exten => s,2,GotoIf($[${LEN(${digits})} > 11]?notrecognized,s,1)
exten => s,3,GotoIf($[${LEN(${digits})} = 11]?fixdigits,s,1)
exten => s,4,GotoIf($[${LEN(${digits})} < 10]?notrecognized,s,1)
exten => s,5,Goto(confirmdigits,s,1)

If there is no input in the variable called ${digits}, I assume that they have no touch tone phone, or something is wrong, and I send that call to a context called ‘sorry’ that plays an apology, and then hangs up the call.

If there is greater than 11 digits, or less than ten digits, the call is sent to a context called ‘notrecognized’, and the caller is asked to enter their digits again.

If there are 11 digits, I send the call to a routine called ‘fixdigits’, where I check to see if the first dialed digit is 1. If it is, I strip it off. My application doesn’t want it. If a caller enters 11 digits, (a valid phone number in North America) I should be smart enough to accept that, and just ignore the leading ‘1’.

A ten digit number would proceed all the way to step 5, where the call would be referred to a context called ‘confirmdigits’ that plays back the caller entered digits, and asks them to confirm their entry.

To me, extension pattern match is simple and more flexible.

[code][general]
NANP = NXXNXXXXXX; "10-digit phone number starting with area code"
NA_LOCAL = NXXXXXX; a North American local #
MY_AREA = 555; local area code

[macro-valid-nanp]
; NANP validation
; USAGE: Macro(valid-nanp,[number],[prompt])
; can be called with or without ${ARG2}
; “Please enter the number you wish to call, then pound.“
exten => s,1,Set(PROMPT=vm-enter-num-to-call&vm-then-pound)
exten => s,n,GotoIf(${ARG2}?:match)
exten => s,n,Set(PROMPT=${ARG2})
; can be called with or without ${ARG1}; use ${MACRO_EXTEN} without
exten => s,n(match),GotoIf(${ARG1}?${ARG1},1:${MACRO_EXTEN},1)
exten => _${NA_LOCAL},1,Goto(1${MY_AREA}${EXTEN},1)
exten => _${NANP},1,Goto(1${EXTEN},1)
exten => _1${NANP},1,Goto(${MACRO_CONTEXT},${EXTEN},$[${MACRO_PRIORITY} + 1])
; handle invalid #
; workaround for not having =~ in 1.2
exten => _Z.,1,Set(NUMBER=$[”${EXTEN}” : “([0-9]+)”])
; exten => _Z.,n,NoOp(${Trail})
exten => _Z.,n,GotoIf(${NUMBER}=${EXTEN}?:${NUMBER},1)
exten => _Z.,n,Set(NUMBER=); reset
exten => _Z.,n,SayDigits(${EXTEN})
; use Background() and matching to allow input either as extension
; or in Read()
; loop back
exten => _Z.,n(input),Playback(privacy-incorrect)
exten => _Z.,n,Read(NUMBER,${PROMPT},15,10)
; calling context needs to handle nil input
exten => _Z.,n,GotoIf(${NUMBER}?${NUMBER},1:${MACRO_CONTEXT},#,1);
[/code]

An example to use this would be like:

exten => s,1,Read(NUMBER,,15,,,10) exten => s,n,Goto(${NUMBER},1) exten => _X.,1,Macro(valid-${ARG3},,${PROMPT}) exten => _X.,n,Dial(Zap/${EXTEN})

Although the macro looks long, the basic idea is captured in 3 lines

exten => _${NA_LOCAL},1,Goto(1${MY_AREA}${EXTEN},1) exten => _${NANP},1,Goto(1${EXTEN},1) exten => _1${NANP},1,Goto(${MACRO_CONTEXT},${EXTEN},$[${MACRO_PRIORITY} + 1])

Much of the macro code is used to deal with invalid input and 1.2 expression queerness.

Yes! That is a much better method.

My method would only verify the length of the phone number entered. However, it does not validate the number at all. For instance, the number 111-111-1111 would be valid in my code, but invalid in valley’s code.

Pardon me while I steal this for my application. 8)