Skip to main content
December 29, 2009
Question

CFinput mask

  • December 29, 2009
  • 2 replies
  • 1165 views

Kind of new at this CF stuff.  I have a text input field where I need the user to input a serial number of a piece of equipment.  It must follow the manufacturers format and be 11 characters.  X999X999999.  Can someone help me with this.  The best i seem to be able to get is a minimum of 11 characters.

<cfinput type="text" name="IDnumber" message="You must enter an 11 character meter number" mask="A999A999999" validateat="onSubmit" required="yes" class="SERIAL"id="IDnumber" maxlength="11" width="240">

Thanks in advance.

    This topic has been closed for replies.

    2 replies

    Inspiring
    December 29, 2009

    For BKBK, the problem is that an entry of less than 11 characters will probably pass through.

    For the OP, you'll have to write your own js function, called when the form is submitted, to ensure that the field has 11 characters.  You don't need a validateat attribute in your input.  The mask attribute will take care of the data entry.

    Inspiring
    December 29, 2009

    The mask attribute uses javascript to constrain what the user can type into the textbox.  It does not validate the contents of the textbox.  You can use the validate and pattern attributes of CFINPUT to use a regular expression to validate your input. See the sample below.  Note that CFINPUT depends on javascript and hidden form fields and this *could* be bypassed by a user.  You should also validate your input on the server side.

    Please let us know if this meets your requirements.

    <cfinput name="idnumber" required="yes" validate="regex" pattern="^[A-Za-z0-9][0-9]{3}[A-Za-z0-9][0-9]{6}$" mask="X999X999999" />

    BKBK
    Community Expert
    Community Expert
    December 29, 2009
    The best i seem to be able to get is a minimum of 11 characters.

    I don't understand. You want 11 characters, you got 11 characters. So what's the problem?

    Inspiring
    December 29, 2009
    The best i seem to be able to get is a minimum of 11 characters.

    I don't understand. You want 11 characters, you got 11 characters. So what's the problem?

    "Minimum of 11 characters" does not fulfil the requirement of the mask also being correct, and the string not also being MORE than 11 characters.

    To the OP: what version of CF?

    --

    Adam

    BKBK
    Community Expert
    Community Expert
    December 29, 2009
    "Minimum of 11 characters" does not fulfil the requirement of the mask also being correct, and the string not also being MORE than 11 characters.

    I understand that even less.