balooka Posted December 6, 2002 Share Posted December 6, 2002 I have to validate some field entries and I was given the calculationcode by my boss. He got it from the account we're working for. Anyway, the problem is, its a PHP validation. The guy that made the calc said that it is possible to create the same one in FM too - but I don't even know where to start. The code is: $number % 9 == 9 - (ord($letter) -54) %9 What the user NEEDS to enter is a 12 digit serialnumber and the first character is a LETTER ((ex: P123456789123). the ORD function replaces the letter with a number (ex. a=1, B=2, c-3 ... z=26). $number are the 11 numbers (without the letter)... Sorry if this is confusing or even an unwanted post since its about PHP too, but I 'm stuck on this thing... JP Ps. Bob Weaver did a great thing for me with the other request about the letter and numbers, but I didn't know then that I had to validate it like this. Link to comment Share on other sites More sharing options...
Newbies EFmorph Posted December 6, 2002 Newbies Share Posted December 6, 2002 Hi, I do a validation for a case like this, which uses Length(FieldName) = 12 and Length(TextToNum(FieldName)) = 11 and TextToNum(FieldName) = Right(FieldName, 11) It works. But I'm afraid I can't help you with the php... Link to comment Share on other sites More sharing options...
balooka Posted December 6, 2002 Author Share Posted December 6, 2002 Thx EFmorph I did have the right calc for the letter+number part, but still thanks. About the PHP: Seems that '%' is a modulo-operator in PHP so I redid the code in fmp to the following: Mod(NumberSerie; 9) = Mod(9 -(ValueLetter-54);9)-1 In short what is does is valdiate serialnumbers, where the MOD of the NUMBERS is equal to the MOD of the LETTER, when the letter is transformed into ASCII. If the outcome of both MODs are the same the serial is valid. A new question arises cause I do not know how to covert letters to ascii in a calculation. I have a few letters ATM so thats easily done, but I'm not planning on doing 54 letters (upper/lowercase) in a [Case] string. If anyone knows how to convert those on the fly in a calc I would really apreciate it. Thank for thinking with me JP Link to comment Share on other sites More sharing options...
BobWeaver Posted December 8, 2002 Share Posted December 8, 2002 If I understand correctly, what you want is exactly like the validation from your earlier post except that it's now one letter plus 11 digits instead of one letter plus 6 digits. If so, and if you are still doing this within Filemaker (as a field validation calc) then the formula that I posted before could be changed to: Length(SerNoField) = 12 and Position("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Left(SerNoField, 1), 1, 1) and (TextToNum("1" & Middle(SerNoField, 2, 11))>100000000000) This may not perform in precisely the same way as the PHP formula, but it accomplishes the same thing. There are no Filemaker functions to directly convert characters into their ASCII codes. You can cobble one together using the Position() function, but it won't do you a lot of good, since you can't do much with the codes in Filemaker once you get them. Link to comment Share on other sites More sharing options...
balooka Posted December 9, 2002 Author Share Posted December 9, 2002 Thanks again Bob, I tried to do the ascii thing in FM but you are right on that - won't do me any good. What I did now was create a case where I manually entered 26 values (only uppercase needed), and included the right side of the original (PHP-) calc. So that calcfield will give me the right outcome based on the serialletter entered (using your code). The left side (also based on your calc) does the MOD-calc on the numbers. The only thing thats bugging me a little is the fact that I had to put a trailing '-1' on the calc [ Mod(NumberSerie; 9) = Mod(9 -(ValueLetter-54);9)-1 ] , I need to put it there but I can't figure out why. Not a big prob, 'cause the calc is working perfectly, it's just bugging me Thanks for all your help Link to comment Share on other sites More sharing options...
djgogi Posted December 9, 2002 Share Posted December 9, 2002 I would use the following: (Mod(serial, 9) = 9 -Mod(64+Position("ABCDEFGHIJKLMNOPQRSTUVWXYZ",Left(serial, 1), 1, 1) -54,9)) and Length("1" & TextToNum(serial)) = Length(serial) and Length(serial)=12 Dj Link to comment Share on other sites More sharing options...
BobWeaver Posted December 9, 2002 Share Posted December 9, 2002 Okay, it looks like the last digit in the serial number is actually a kind of checksum. I didn't notice that before. Link to comment Share on other sites More sharing options...
Recommended Posts
This topic is 7943 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now