Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

I have an input system in FMP11 that uses a dialog box with a global field to input quantities for each record. On click OK the script will add the value in the record proper field.
 
The users should enter just one number in that dialog box global field (e.g.: "10" or "-10").
 
I'm trying to create a validation script to make sure that the users don't type weird stuff except that one number.
 
(It happened that they typed expressions and spaces, making the system fail. e.g.: "+10-5+ 30- 15" ).
 
So far I got to his:
 
Once typed the value in the Custom dialog  GLOBALFIELD and click OK ->
 

If [(Lenght ( Filter ( Lower ( GLOBALFIELD ) ; "1234567890-" ) )) = ( Lenght ( GLOBALFIELD) )) ) and ( Patterncount ( GLOBALFIELD ; "-" ) ≤ 1 )]
 
      Set Field ( RECORDFIELD ; RECORDFIELD + GLOBALFIELD)
 
Else
 
      Error message and Exit Script
 
End If

 

 
On my tests everything looks fine but I would appreciate any comment from an external eye.
 
Thank you all for your help.
 
Have a great day.

Posted

I did try with the "getasnumber" function as described: GetAsNumber ( field )  = field

 

However, when I tested it, the system sees "10-5+3" equal as "1053", which is not what I need.

 

Perhaps I could add "Lenght" to improve the matching value?

Posted

But the complete test

getasnumber( field ) = field

would fail when the user types in 10-5+3, so it does not matter that getasnumber( ) treats it as 1053

Posted

I did try with the "getasnumber" function as described: GetAsNumber ( field )  = field

 

If you had read entire thread, you would have seen that GetAsNumber() isn't helpful in this case.

 

If you haven't, the part to which I linked is:

 

Well, you could validate that the entry contains only digits, a decimal point and a minus sign. And that there's no more than one decimal point and/or minus sign. And that the minus sign, if present, is before any other character. Uhm, what else could wrong?

 

Your calculation attempts to do the first part (just without the decimal point) by =

 

Lenght ( Filter ( Lower ( GLOBALFIELD ) ; "1234567890-" ) )) = ( Lenght ( GLOBALFIELD) ))

 

which is not a valid syntax, and even if it were, the same thing could be accomplished much more simply by =

Filter ( GLOBALFIELD ; "1234567890-" ) = GLOBALFIELD

Next, you have =

 

Patterncount ( GLOBALFIELD ; "-" ) ≤ 1

 

which is a step in the right direction, but on its own it will pass an entry of "123-567". A better approach would also check for =

Position ( GLOBALFIELD ; "-" ; 1 ; 1 ) ≤ 1

to make sure that the minus sign, if present, is the first character of the entry.

  • Like 1
Posted

Perhaps I read the thread too fast and I didn't get the whole picture.

 

You are absolutely right! Right now the script check the typed input as follow:

 

(Filter ( GLOBALFIELD  ; "1234567890-" )  =  GLOBALFIELD) and ( Position ( GLOBALFIELD ; "-" ; 1 ; 1 ) ≤ 1 )
 
Everything works smooth with all the tests. Thank you!!!
Posted
 (Filter ( GLOBALFIELD  ; "1234567890-" )  =  GLOBALFIELD) and ( Position ( GLOBALFIELD ; "-" ; 1 ; 1 ) ≤ 1 )

 

That's not quite enough, as it will pass an entry of "-123-45" as valid. As I said,

 

 A better approach would also check for =

Position ( GLOBALFIELD ; "-" ; 1 ; 1 ) ≤ 1

to make sure that the minus sign, if present, is the first character of the entry.

 

you need to combine the tests, so that eventually the full test reads as =

Filter ( GLOBALFIELD ; "1234567890-" ) = GLOBALFIELD
and
PatternCount ( GLOBALFIELD ; "-" ) ≤ 1
and
Position ( GLOBALFIELD ; "-" ; 1 ; 1 ) ≤ 1

Note that this does NOT pass "123.45" or even "123.0".

 

---

P.S. Are you getting a wholesale discount on parentheses?

  • Like 1
Posted

BTW, although your entry is scripted and using a global field as a "buffer", you could still take advantage of Filemaker's native "Strict data type: [Numeric Only]" validation, by capturing the error when the actual number field is set, say :

...
Set Field [ YourTable::Numberfield; AnyTable::GLOBALFIELD ]
If [ Get ( LastError ) = 502 ]
 Beep
 ... 
Else
 Commit Records/Requests
 ...
End If
...

Note that Numberfield must be set to Validate Always in order for this to work.

  • Like 1
Posted

Thank you again for the further details. I thought that "Patterncount" was going to fit somewhere..

 

As the system needs to record SKU quantities I won't need to let pass decimal values.

 

..Yes I do like parenthesis.. :)  when I get lost in creating calculations I prefer to keep things clearly separated. I may clean them up afterwards.

This topic is 3578 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.