Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFML select only 3 int from form.zipcode

I know this is probably easy but how to would I select only the first 3 digits from a form field called zipcode when I do #form.zipcode#

I would prefer this to be in cfml if possible.

Example 03954 becomes 039

This is for doing shipping calculations.

Thanks in advance.

like image 839
Thomas Nichols Avatar asked Jan 28 '26 12:01

Thomas Nichols


1 Answers

Very easy, use the built-in left() function.

Tags:

<cfset fullZipCode = trim(form.zipcode) />    
<cfset firstThree = left(fullZipCode, 3) />    
<cfdump var="#firstThree#" />

or in cfscript

<cfscript>    
  fullZipCode = trim(form.zipcode);     
  firstThree = left(fullZipCode, 3);     
  writeDump(var="#firstThree#");
</cfscript>

Docs: https://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e3a.html

like image 70
Alex Baban Avatar answered Jan 31 '26 04:01

Alex Baban



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!