Skip to main content
Participant
August 24, 2011
Question

cfproperty validateparams help?

  • August 24, 2011
  • 1 reply
  • 507 views

Hi! I'm trying to figure out what I'm doing wrong here. I'm setting up ORM on a table. I'm using the same regex to validate serverside and clientside, but when I submit and a value passes clientside validation, I get an error:

The value does not match the regular expression pattern provided.

Here's the property in question:

<cfproperty name="name"             fieldtype="column"             column="user_name"             length="16"             ormtype="string"             update="true"             insert="true"             optimisticlock="true"             validate="regex"             validateparams="{                   minlength=6,                   maxlength=16,                   pattern=[A-Za-z0-9_]                   }">

The input going into this is this:

<cfinput name="username"          maxlength="16"          length="16"          required="true"          message="Invalid Username"          tooltip="Your username must be between six and sixteen characters and can include only letters, numbers, and underscores."          validate="regex"          validateat="onSubmit"          type="text"          pattern="[A-Za-z0-9_]">

And then sticking them together:

<cfscript>         user = EntityNew("User");         user.setname("formdata.username");         EntitySave(user);         ormflush(); </cfscript>

Since I'm using the same regex both places, I'm not sure why an error is being thrown? The client-side validation seems to be working perfectly, so did I mess something up setting up the property?

Thanks for taking a moment to read this far. I'm stumped.

    This topic has been closed for replies.

    1 reply

    Participant
    August 24, 2011

    As an update, I can validate the username form field using this cfparam:

    <cfparam name = "formdata.username"          pattern = "[A-Za-z0-9_]"          type = "string">

    Meaning the following work:

    <!---Serverside validation of username field using cfparam--->

    <cfparam name = "formdata.username"          pattern = "[A-Za-z0-9_]"          type = "string">

    <!---Client-side validation of username field--->

    <cfinput name="username"       validate="regex"       validateat="onSubmit"       type="text"       pattern="[A-Za-z0-9_]"      >

    But this doesn't?

    <!---username cf property for username---!>

    <cfproperty  name="name"           fieldtype="column"           column="user_name"           length="16"           ormtype="string"           update="true"           insert="true"           optimisticlock="true"           validate="regex"           validateparams="{           minlength=6,           maxlength=16,           pattern=[A-Za-z0-9_]           }">