Adobe COLDFUSION 9 Manual page 765

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
• The
attribute of the form element
name
• The value of the control to validate
For example, if you write the
<cfinput type="text"
...
<!--- Do not include () in JavaScript function name. --->
onvalidate="handleValidation"
...
>
You define the JavaScript function as the following:
<script>
<!--
function handleValidation(form_object, input_object, object_value) {
...
}
//-->
</script>
Example: validating a password
The following example validates a password. The password must have at least one of each of the following: an
uppercase letter, a lowercase letter, and a number. It must be from 8 through 12 characters long. If the password is
invalid, the browser displays a message box. If the password is valid, it redisplays the page with a brief success message.
Use JavaScript to validate form data
Create a ColdFusion page with the following content:
1
<html>
<head>
<title>JavaScript Validation</title>
<!--- JavaScript used for validation. --->
<script>
<!--
// Regular expressions used for pattern matching.
var anUpperCase = /[A-Z]/;
var aLowerCase = /[a-z]/;
var aNumber = /[0-9]/;
/* The function specified by the onValidate attribute.
Tests for existence of at least one uppercase, lowercase, and numeric
character, and checks the length for a minimum.
A maximum length test is not needed because of the cfinput maxlength
attribute. */
function testpasswd(form, ctrl, value) {
if (value.length < 8 || value.search(anUpperCase) == -1 ||
value.search (aLowerCase) == -1 || value.search (aNumber) == -1)
{
return (false);
}
else
{
return (true);
}
tag as the following:
cfinput
Last updated 8/5/2010
760

Advertisement

Table of Contents
loading

Table of Contents