Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex in CFIF 1

Status
Not open for further replies.

CTekMedia

Programmer
Oct 5, 2001
634
0
0
US
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.

Thanks oh brilliant ones.



Cheers,

Bluetone
 
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>

I am sure it must be better ways :)

Jonas
 
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.

Thanks much John

Cheers,

Bluetone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top