text field number only regex or js validation

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
swiftinitpvtltd
Posts: 370
Joined: Sat Apr 28, 2018 3:33 am
Location: India
Contact:

text field number only regex or js validation

Post by swiftinitpvtltd »

I have a text type text field but I want user to only type number. How to stop user from putting abc... Is there any regex?
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: text field number only regex or js validation

Post by BobK »

You have at least 2 options for this.

Option 1
This option will not initially stop them from entering non-numeric characters, but they will get an error when trying to save the form.
Enter a rule like the following on your BO

Code: Select all

If MATCHES(BO.NumericField, '^[0-9]*$')='No' Then
REPORT ERROR 'NumericField MUST BE Numeric'
Option 2
Set the "Input mask" of your field to accept only numeric digits and the user will be unable to enter anything but numbers.
The mask character 0 will accept any digit between 0 and 9.
The problem with this option is that you will need to set the mask to accept the maximum number of characters. For example '000000000' would be needed to be able to enter 9 digits.
If the user enters less digits then the maximum allows, the entry symbol will still display for the remaining digits.
Bob
PointsWell
Posts: 1457
Joined: Tue Jan 24, 2017 5:51 am
Location: 'Stralya

Re: text field number only regex or js validation

Post by PointsWell »

Or use the Validate as. This will not stop the user typing non numerics but it will generate a validation error on save.
Screen Shot 2020-07-08 at 07.59.45.png
Screen Shot 2020-07-08 at 07.59.45.png (34.55 KiB) Viewed 5235 times
Additional Regex validations can be added to the UIConfig.props file

Code: Select all

TextInputMask1=US Phone\#/\\(?\\d{3}\\)? ?\\d{3}[-.]\\d{4}/
TextInputMask2=Numeric\#/[0-9]*/i
TextInputMask3=ISTC\#/\\([A-F0-9]{3})-\\d{4}-([A-F0-9]{8})-([A-F0-9]{1})/
swiftinitpvtltd
Posts: 370
Joined: Sat Apr 28, 2018 3:33 am
Location: India
Contact:

Re: text field number only regex or js validation

Post by swiftinitpvtltd »

Thank you all. Multiple options in aware!
Post Reply