Skip to main content
Inspiring
December 5, 2006
Question

Checking for cf nput character length

  • December 5, 2006
  • 1 reply
  • 263 views
I am trying to create a function that will check to see if a <cf input type = text> is exactly 6 characters long. I need my webpage to throw an error/popup a message when a user clicks "Submit" and the input field has a value not equal to 6 characters. Is this something that can be done with coldfusion or does it have to be done purely in javascript? Any help would be appreciated. Another concern I have is that the name of the <cfinput type = text> is:
'ItemID#getIDDetails.ItemID#_DetailID#getIDDetails.ID#'
I'm not sure how to plug this name into a function to or <cfif isdefined> condition. Can javascript accept an input such as this?
Attached is the code for my <cfinput>. Also attached is the javascript code I've been trying to program as well as a coldfusion variant.
This topic has been closed for replies.

1 reply

December 5, 2006
If you use cfinput, you don't need to write any javasccript at all (CF writes it for you).

Use the following (EXACTLY) to get 6 digits required:

<CFINPUT
value = '#isSetValue#'
type = 'text'
validate = 'regular_expression'
pattern = '[0-9]{6}'
validateat = "onBlur,onServer,onSubmit"
message = 'Please enter exactly six digits for #trim(getIDDetails.ItemName)#.'
name = 'ItemID#getIDDetails.ItemID#_DetailID#getIDDetails.ID#'
width = '50'
class = 'NewImput_no_width'
/>

VinceManAuthor
Inspiring
December 5, 2006
Works like a charm! Thank you very much