Solved

Specific String search Coldfusion

Posted on 2012-12-27
4
254 Views
Last Modified: 2012-12-27
Hi all,

Can someone help me create the following CF Function?

We receive payments from clients but the client number can be anywhere in the description.
The naming convention of the client number is: yyyynnn where yyyy is the year and nnn is a sequence number between 001 and 999. The year can be between 1960 and the current year. There may be other numbers in the description but the client number should be returned only when the above criteria is met.

Thanks in advance.

Errol
0
Comment
Question by:Errol Farro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 38723672
You'll likely need a regex. You should add that topic to the question tags to attract attention from the right experts. (I'm not a regex guru so I'll leave this to someone more qualified :)
0
 
LVL 13

Accepted Solution

by:
ansudhindra earned 375 total points
ID: 38723707
check this..
<cfoutput>
  <cfset sourceString="This is a demo string and customer number is not 4537825 but it is 1998893 and not 19989990. Did you got it?" />
  Customer number from function is  #getCustomerNumber(sourceString)#.
</cfoutput>

<cffunction name="getCustomerNumber" returntype="numeric">
  <cfargument name="sourceString" required="true" type="string" />
  
  <cfset startYear = 1960 />
  <cfset endYear = dateformat(now(),'yyyy') />
    
  <cfset arrSearch = rematch("[\d]+",sourceString)>
  <cfset customerNumber = 0 />
  
  <cfloop from="1" to="#arraylen(arrSearch)#" index="i" step="1">
    <cfset cv = arrSearch[i] />
    <cfif len(trim(cv)) eq 7>
     <cfif ((left(cv,4) gte startYear) and (left(cv,4) lte endYear)) and ((right(cv,3) gt 0) and (right(cv,3) lt 1000))>
        <cfset customerNumber = cv />
        <cfreturn customerNumber />
     </cfif>
    </cfif>
  </cfloop> 
  <cfreturn customerNumber />
</cffunction>

Open in new window

0
 

Author Closing Comment

by:Errol Farro
ID: 38723787
Thanks a lot Ansudhindra. Works like a charm....
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38723970
> "[\d]+"

May as well search for 7 digits exactly instead of *any* number of digits.

And if you go with a cffunction, don't forget to VAR scope all those variables... or you can end up creating weird threading bugs in some cases.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
multi page pdf 4 108
need help with one more  outer join sql query in coldfusion 4 65
CFFILE upload help 98 208
Coldfusion builder and IIS 2 39
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question