|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Evaluating Strings
I have 4 text fields all named serialnum. When the user enters theirJennifer Schlender 05/21/04 04:41 P After the strings all pass the RE, do something like this (shot from theBarney Boisvert 05/21/04 04:52 P That worked PERFECT! I have struggled with this for a while and no one has been able to help :-( Thanks!Jennifer Schlender 05/21/04 05:23 P 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! After the strings all pass the RE, do something like this (shot from the 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 ----- Excess quoted text cut - see Original Post for more ----- That worked PERFECT! I have struggled with this for a while and no one has been able to help :-( Thanks! ----- Excess quoted text cut - see Original Post for more -----
|
February 09, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||