hip, with no testing):
<cfset s = structNew() />
<cfloop list="#form.serialnum#" index="num">
<cfset prefix = left(num, 3) />
<cfset num = removeChars(num, 1, 3) />
<cfif structKeyExists(s, prefix)>
<cfset s[prefix] = listAppend(s[prefix], num) />
<cfelse>
<cfset s[prefix] = num />
</cfif>
</cfloop>
<cfloop collection="#s#" item="prefix">
<cfif listLen(s[prefix]) GT 1>
<cfset s[prefix] = listSort(s[prefix], "numeric") />
<cfset last = -10 />
<cfloop list="#s[prefix]#" index="num">
<cfif num - last LTE 5>
<cfthrow type="InvalidSerialException"
message="the #prefix##num# serial is invalid" />
</cfif>
<cfset last = num />
</cfloop>
</cfif>
</cfloop>
<cfoutput>the serials are all valid</cfoutput>
Cheers,
barneyb
> -----Original Message-----
> From: Jennifer Schlender [mailto:[EMAIL PROTECTED]
> Sent: Friday, May 21, 2004 1:41 PM
> To: CF-Talk
> Subject: Evaluating Strings
>
> I have 4 text fields all named serialnum. When the user enters their
> serial numbers, on the next page I make sure that the numbers match
> to a corresponding regular _expression_. If one does not match, then
> the user is notified that they entered a wrong serial number and
> should enter it again. If they all pass the regex, they get inserted
> into a table. Well, I need to either evaluate those numbers before I
> insert or pull them back out and make sure that none of them are
> within 5 digits of each other. Example list:
> 3M0123456789, 2KB234234345, 22L897657898, 3M0123456790. All of these
> serial numbers are contained on one invoice. I would need to flag
> this invoice as the first number in the list is 1 digit lower than
> the last number and the first 3 characters match. I have attempted to
> do my insert first, and then compare the group by selected them again
> and doing a loop, but I can't get that to work. Any ideas?
>
> Thanks!
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

