Jump to content

I do NOT know what to do with this


This topic is 7900 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

  • Newbies

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... crazy.gif

Link to comment
Share on other sites

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 smile.gif

JP

Link to comment
Share on other sites

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

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 smile.gif

Thanks for all your help

Link to comment
Share on other sites

This topic is 7900 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.