Validating textbox prompts
There is a report with a textbox prompt. Users are expected to enter a phone number in (nnn)nnn-nnnn format in that prompt.
In this recipe, we will write a code to validate the value entered by the user and submit the report only if the value entered is in specified format.
Getting ready
Pick any report and add a textbox prompt to it. We will add a JavaScript to validate that textbox.
How to do it...
Wrap the textbox prompt within a SPAN in the same way as we did in prior recipes.
Add the following script to the page footer:
<script> function ValidatePage() { var theSpan = document.getElementById("A1"); var a = theSpan.getElementsByTagName("input"); /* this captures the textbox */ for( var i = a.length-1; i >= 0; i-- ) { var link = a[i]; if( link.id.match(/PRMT_TB_/)) {phoneRegex = /^\(\d{3}\) \d{3}-\d{4}$/; /* This is regular expression to allow only the strings in (nnn) nnn-nnnn format */ if( !link.value.match( phoneRegex ) ) { ...