Example: Validating An E-Mail Address - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Example: validating an e-mail address

The following example validates an e-mail entry. If the string is invalid, it displays a message box.
If the address is valid, it redisplays the page. To be valid, the e-mail address must not be an empty
string, contain an at sign (@) that is at least the second character, and contain a period (.) that is at
least the fourth character.
To use JavaScript to validate form data:
Create a ColdFusion page with the following content:
1
<html>
<head>
<title>JavaScript Validation</title>
<script>
<!--
function testbox(form, ctrl, value) {
if (value == "" || value.indexOf ('@', 1) == -1 ||
value.indexOf ('.', 3) == -1)
{
return (false);
}
else
{
return (true);
}
}
//-->
</script>
</head>
<body>
<h2>JavaScript validation test</h2>
<p>Please enter your email address:</p>
<cfform name="UpdateForm" preservedata="Yes"
action="validjs.cfm" >
<cfinput type="text"
name="inputbox1"
required="YES"
onvalidate="testbox"
message="Sorry, your entry is not a valid email address."
size="15"
maxlength="30">
<input type="Submit" value=" Update... ">
</cfform>
</body>
</html>
Save the page as validjs.cfm.
2
View validjs.cfm in your browser.
3
Input validation with JavaScript
615

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents