Page 1 of 1

Validate date entered

Posted: Mon Apr 27, 2009 1:11 am
by amitkhosla
Hi

I want to validate that the user does not enter any previous date.

Here is the code that takes the date input from user
<field name="appDate" type="digits?length=8">
<prompt>
<voice name="crystal">
<break size="medium" />
Enter the date in year month day format, of your appointment.
For example for 18 Feburary 1983 enter <say-as type="acronym">19830218</say-as>
</voice>
</prompt>
<filled>
<assign name="appointmentDate" expr="appDate.substr(4,2)+'/'+appDate.substr(6,2)+'/'+appDate.substr(0,4)"/>
</filled>
</field>


Now how and where to validate the user date is not less than previous date??

Regards,
Amit

IVR code for validating a date entered

Posted: Mon Apr 27, 2009 10:18 am
by support
Hi,

You can use the IVR tag, <if>, to set up conditionals within your VXML script. Use this IVR code for example.

validatedate.php:

Code: Select all

<?php
header("Content-type: text/xml");
echo("<?xml version=\"1.0\"?>\n");
?>
<vxml version="2.0">
<form>

<var name="prevDate" expr="19820118"/>

<field name="appDate" type="digits?length=8">
<prompt>
<voice name="crystal">
<break size="medium"/>
Enter the date in year month day format, of your appointment.
For example for 18 Feburary 1983 enter <say-as type="acronym">19830218</say-as>
</voice>
</prompt>

<filled>
<if cond="appDate > prevDate">
<assign name="appointmentDate" expr="appDate.substr(4,2)+'/'+appDate.substr(6,2)+'/'+appDate.substr(0,4)"/>
<prompt>
The appointment date is <value expr="appointmentDate"/>.
</prompt>
<else/>
<prompt>
You have entered a previous date.
</prompt>
</if>
</filled>
</field> 

</form>
</vxml>
Hope this helps.

Regards,
Plum Support

Validate date entered

Posted: Mon Apr 27, 2009 2:01 pm
by amitkhosla
Thanks for thesolution, but what i was wondering is that how will i get the current date & time to check if the date entered is not less than todays date and current time

regards,
amit
support wrote:Hi,

You can use the <if> tag to set up conditionals within your VXML script. For example:

validatedate.php:

Code: Select all

<?php
header("Content-type: text/xml");
echo("<?xml version="1.0"?>\n");
?>
<vxml version="2.0">
<form>

<var name="prevDate" expr="19820118"/>

<field name="appDate" type="digits?length=8">
<prompt>
<voice name="crystal">
<break size="medium"/>
Enter the date in year month day format, of your appointment.
For example for 18 Feburary 1983 enter <say-as type="acronym">19830218</say-as>
</voice>
</prompt>

<filled>
<if cond="appDate > prevDate">
<assign name="appointmentDate" expr="appDate.substr(4,2)+'/'+appDate.substr(6,2)+'/'+appDate.substr(0,4)"/>
<prompt>
The appointment date is <value expr="appointmentDate"/>.
</prompt>
<else/>
<prompt>
You have entered a previous date.
</prompt>
</if>
</filled>
</field> 

</form>
</vxml>
Hope this helps.

Regards,
Plum Support

IVR code to validate date entered

Posted: Mon Apr 27, 2009 2:33 pm
by support
Hi,

You can use the following IVR example of IVR code that uses the IVR tag, <if>, to help you achieve this.

validatedate.php:

Code: Select all

<?php
header("Content-type: text/xml");
echo("<?xml version=\"1.0\"?>\n");
?>
<vxml version="2.0">
<form>

<script>
  var currentTime = new Date();
  var month = currentTime.getMonth() + 1;
  var day = currentTime.getDate();
  var year = currentTime.getFullYear();
  if (month < 10){
  month = "0" + month;
  }
  if (day < 10){
  day = "0" + day;
  }
  currentTime = year + month + day;
</script> 

<field name="appDate" type="digits?length=8">
<prompt>
<voice name="crystal">
<break size="medium"/>
Enter the date in year month day format, of your appointment.
For example for 18 Feburary 1983 enter <say-as type="acronym">19830218</say-as>
</voice>
</prompt>

<filled>
<if cond="appDate > currentTime">
<assign name="appointmentDate" expr="appDate.substr(4,2)+'/'+appDate.substr(6,2)+'/'+appDate.substr(0,4)"/>
<prompt>
The appointment date is <value expr="appointmentDate"/>.
</prompt>
<else/>
<prompt>
You have entered a previous date.
</prompt>
</if>
</filled>
</field> 

</form>
</vxml>
Hope this helps.

Regards,
Plum Support