Skip to main content
Inspiring
March 19, 2008
Answered

Validation with Regular Expressions

  • March 19, 2008
  • 2 replies
  • 1506 views
I am trying to validate data using regular expressions.
here is a copy of the code.

<cfinput type="text" name="FQID_#ATTRIBUTES.FQID#_officer" width="36" validate="regular_expression" pattern="^\bna\b$|^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$" required="#ATTRIBUTES.required#" enabled="yes" message="0.0 to 100 or na, Required" value="#ATTRIBUTES.FQID_Response.Officer#" style="textAlign:right;" onchange="removeDash(FQID_#ATTRIBUTES.FQID#_officer);"/>

I do not get any errors but I am still able to enter anything I want into the text box. I am trying to limit it to a number between 0 and 100 and excepts decimal amount. It also needs to accept na if it is not applicable. As it stands now I can enter anything.
This topic has been closed for replies.
Correct answer Luckbox72
Luckbox72,

Regular expression validation is not compatible with flash forms.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_i_07.html#1100379

Thanks, that explains it.

2 replies

Participating Frequently
March 21, 2008
What is your latest one?
Luckbox72Author
Inspiring
March 21, 2008
(^na$)|^(\d(\.\d+)?|\d\d(\.\d+)?|1\d\d)$

I also changed it to ^(\d(\.\d+)?|\d\d(\.\d+)?|1\d\d)$ and tried and it still accepted alpha characters
Inspiring
March 21, 2008
Luckbox72,

I suspect that validation is not occurring. I am using CF7 and IE7 and the sample I posted only allows "na" or a numeric value. Try the following.
1. verify that javascript is enabled on your browser
2. verify that you can browse to CF's javascript validation files, usually at /CFIDE/scripts/cfform.js
3. see if non-regular expression javascript validation works
4. post the code for your entire page, if this is not possible create a page to test only this regular expression (like the sample I posted) and see if it validates.
Luckbox72Author
Inspiring
March 19, 2008
Ok I did find an error in the reg eqpression. I have tested this version with an online tester and it works as it should but still when I try to use it as the pattern for my validation it does not validate the string. I can still type anything I want.

/^na$|[1-9]{1}([0-9]{0,3})?\.[0-9]{1,2}$/
Inspiring
March 19, 2008
Try adding the range attribute to your cfinput tag.

Luckbox72Author
Inspiring
March 19, 2008
When I put the range in it only allows numeric entries. I still need to allow the user to enter na.