text field number only regex or js validation
-
- Posts: 370
- Joined: Sat Apr 28, 2018 3:33 am
- Location: India
- Contact:
text field number only regex or js validation
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?
Re: text field number only regex or js validation
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
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.
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'
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
-
- Posts: 1457
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: text field number only regex or js validation
Or use the Validate as. This will not stop the user typing non numerics but it will generate a validation error on save.
Additional Regex validations can be added to the UIConfig.props file
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})/
-
- Posts: 370
- Joined: Sat Apr 28, 2018 3:33 am
- Location: India
- Contact:
Re: text field number only regex or js validation
Thank you all. Multiple options in aware!