Restricting Input Field to Numeric Values Only

advanced-prototyping

#1

Hi all

I’m just wondering what the quickest way is to restrict an input field to numeric values only is?

I’ve tried changing the field input type to ‘number’ and ‘phone number’ however I have the following issues.

Number:

  • I don’t want the up/down increment buttons to display

Phone Number:

  • Allows the input of non numeric (alpha characters).

Additional Logic:

Essentially I’m looking for the user to input a numeric value here to 2 d.p as such I have some additional logic:

  • Initial field value is set to 0.00
  • On lost focus if blank sets text on field back to 0.00
  • On lost focus if .00 is not present in users entry this should append to the end of the users entered value
  • On mobile I want on focus the user to be presented with the numeric keypad

As such I believe the Phone Number field type is my best route to solve this however I’m struggling to restrict the input type to numeric only (I don’t want to allow input then remove after/on lost focus) as there will be a series of these field on a page which will be totalled as the user inputs values.

Any help much appreciated.

Thanks

Kyle
Field.rp (53.6 KB)


#2

Hi Kyle -

I don’t know how to make the numeric keyboard come up for mobile, but you can restrict entry of keys by testing for them OnKeyDown. Basically you test for various keys or key combinations; only keystrokes that don’t pass the test will be allowed. (You don’t need a command after the condition.)

The following will allow only numbers, the decimal place, and keystrokes that perform normal field operations (e.g., selecting all with ctrl+a, copying, pasting, etc.):


I know, not intuitive.

Live sample.

File: numbers_only_field.rp (59.6 KB)


#3

Hey Joseph

Thanks for taking the time out to get back to me and to put the RP together - very helpful.

I’ve never used the ‘onkeydown’ function before so thanks for the explanation of how it works.

This also made me laugh… “I know, not intuitive” (Amen, to that).

Thanks

Kyle :slight_smile:


#4

Glad I could help! I already had the field made, so it didn’t take much time.


#5

Hi!

I updated this to allow numbers from the keypad in addition to those on the keyboard’s top number row. (OnKeyDown sees these as different keys.)

numbers_only_field (1).rp (59.3 KB)


Currency Formatting!
closed #6

unlisted #7