How to validate maximum length of a Text Box in ColdFusion

cfinput - use maxLength in input type text

cfinputTypeTextMaxLength.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cfinput type text: how to use maxLength in input type text in coldfusion</title>
</head>

<body>
<h2 style="color:SaddleBrown; font-style:italic">cfinput type text example: how to use maxLength</h2>
<hr width="475" align="left" color="RosyBrown" />
<br />

<cfif IsDefined("Form.SubmitFlower")>
 <cfoutput>
  <h3 style="color:DeepPink;">
      Your favorite flower is: : #Form.Flower#
  </h3>
    </cfoutput>
</cfif>

<cfform name="InputTypeTextMaxlengthTest" method="post" format="html">
 <table border="1" cellpadding="5" cellspacing="0" bordercolor="IndianRed">
     <tr>
         <td colspan="2" bgcolor="SaddleBrown" style="color:Snow; font-size:large" align="center">
             Flower Submit Form
            </td>
        </tr>
     <tr>
         <td style="color:IndianRed; font-weight:bold">
             Favorite Flower
            </td>
         <td>
    <cfinput 
                 name="Flower" 
                    type="text" 
                    style="background-color:Wheat; color:DeepPink; width:250px; height:25px; font-size:large; font-style:italic; font:'Comic Sans MS', cursive"
                    required="yes"
                    message="Input flower name"
        maxlength="7"
                    >
            </td>
        </tr>
     <tr>
         <td colspan="2" align="right">
       <cfinput 
                 name="SubmitFlower" 
                    type="submit" 
                    value="Submit"
                    style="height:45px; width:150px; font-size:large; font-style:italic; font-weight:bold; color:DeepPink;"
                    >
            </td>
        </tr>
    </table>
</cfform>
</body>
</html>













More ColdFusion examples