How does one put a regular expression in a CFIF statement? I'm looking to do form validation and, for example, want to limit the input on a certain field to
[0-9][0-9][A-Z][A-Z] (nnAA). In other words, custom masks.
What I have done is to use ReFind (or whatever is suitable).
<cfif IsDefind("Form.field")>
<cfif NOT Refind("regex, Form.field")
action if False
</cfif>
</cfif>
That works extremely well. I'll post my working code here for anyone doing a search later.
<CFIF NOT REFind("[0-9][0-9][A-Z][A-Z]", "#FORM.SLocation#")>
<CFLOCATION URL="Error3.cfm">
</CFIF>
This checks the field input (FORM.SLocation). If it is two numbers followed by two letters processing continues. If not, users are redirected to another page - error2.cfm.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.