You are viewing limited content. For full access, please sign in.

Question

Question

Forms - Force user to put an even number into a number field

asked on August 3, 2023

Hello,

Have a weird one here. What would be the simplest way to set up a number field on a form so that it will only accept even numbers? 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on August 3, 2023

You can use a regular expression with a single line field and do:
^\d*[02468]$

 

3 0
replied on August 4, 2023

This is what I ended up going with. I didn't include that this field in question is in a table, and is involved in calculations. So what I did was add a text field with the regular expression you mentioned. Then I took my number field that I already had and gave it a formula to copy whatever was input in the text field for that same row, and also made this number field hidden. So I can continue to use my original number field in my calculations, but use the text field to get the input with the constraint on it.

Thanks!

0 0
replied on August 4, 2023

Glad it worked for you! You can also put the variable in a VALUE() formula to do calculations on single line fields smiley

For example:
=SUM(VALUE(SingleLine))

0 0
replied on August 7, 2023

Much nicer than my suggestion.  Thank you!

0 0

Replies

replied on August 3, 2023

I figured out a way, but I'm not sure it is the simplest.

I have a field for the enter an even number.

Another field that divides that number by 2.

A field that is a text field that is the divided by 2 number.  

And an HTML field that says, "Please enter an even number" when the field divided by 2 has a "." in it.

But I hide always and save data for DivideNumber by 2 and Divideby2Result.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.