<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='VoiceXMLSimple.xsl' ?>
<vxml version="1.0">
 <form id="get_card_info">
  <block> We now need your credit card type, number, and expiration date.</block>
  <field name="card_type">
   <prompt count="1">What kind of credit card do you have?</prompt>
   <prompt count="2">Type of card?</prompt>
   <!-- This is an in line grammar. -->
   <grammar><![CDATA[
    visa {visa}
    | master [card] {mastercard}
    | amex {amex}
    | american [express] {amex}
   ]]></grammar>
   <help> Please say Visa, Mastercard, or American Express. </help>
  </field>
  <!-- The grammar for type="digits" is built in. -->
  <field name="card_num" type="digits">
   <prompt count="1">What is your card number?</prompt>
   <prompt count="2">Card number?</prompt>
   <catch event="help">
    <if cond="card_type == 'amex'">
     Please say or key in your 15 digit card number.
    <else/>
     Please say or key in your 16 digit card number.
    </if>
   </catch>
   <filled>
    <if cond="card_type == 'amex' &amp; card_num.length != 15">
     American Express card numbers must have 15 digits.
     <clear namelist="card_num"/>
     <throw event="nomatch"/>
    <elseif cond="card_type != 'amex' &amp; card_num.length != 16"/>
     Mastercard and Visa card numbers have 16 digits.
     <clear namelist="card_num"/>
     <throw event="nomatch"/>
    </if>
   </filled>
  </field>
  <field name="expiry_date" type="digits">
   <prompt count="1">What is your card's expiration date?</prompt>
   <prompt count="2">Expiration date?</prompt>
   <help>
    Say or key in the expiration date, for example one two oh one.
   </help>
   <filled>
    <!-- validate the mmyy -->
    <var name="mm"/>
    <var name="i" expr="expiry_date.length"/>
    <if cond="i == 3">
     <assign name="mm" expr="expiry_date.substring(0,1)"/>
    <elseif cond="i == 4"/>
     <assign name="mm" expr="expiry_date.substring(0,2)"/>
    </if>
    <if cond="mm == '' || mm &lt; 1 || mm > 12">
     <clear namelist="expiry_date"/>
     <throw event="nomatch"/>
    </if>
   </filled>
  </field>
  <field name="confirm" type="boolean">
   <prompt>I have <value expr="card_type"/> number <value expr="card_num"/>,
    expiring on <value expr="expiry_date"/>. Is this correct?
   </prompt>
   <filled>
    <if cond="confirm">
     <submit next="place_order.asp" namelist="card_type card_num expiry_date"/>
    </if>
    <clear namelist="card_type card_num expiry_date acknowledge"/>
   </filled>
  </field>
 </form>
</vxml>
