236
Views
10
Comments
Input Validation that allows only numbers to be entered with input type search


I want to implement the functionality so that the input box (type search) does not let the user enter any letters/alphabets and only allows numbers(in text type)

2025-01-09 14-56-57
IQ78

hi,

here u go:

https://www.outsystems.com/forums/discussion/78790/allow-user-only-put-numbers-on-input-widget/

2023-04-17 05-19-55
Vaishali Shrivastava

Hi @Syeda Aliha Naeem ,


Please check the oml file.

Hope this will help you

Demo1.oml
2023-03-31 06-39-46
Asad Sheikh

Hi @Syeda Aliha Naeem ,

I have attached the OML, Hope this will help.

Asad

InputNumber.oml
2025-04-26 17-49-02
Carlos Victor

I tried this and success!!

Thanks @Asad Sheikh 

2026-02-16 05-51-10
Sahana K

Hi Syeda Aliha Naeem ,

I have attached the oml for your issue , please look into it.

InputNumber.oml
2024-10-03 06-54-46
PRAVEEN RAJKUMAR

@Syeda Aliha Naeem Use this js to restrict Alphabets and to enter only numbers in input field.

var

output=document.activeElement.id

document.getElementById(output).value=document.getElementById(output).value.replace(/[^0-9#@_\-/()./s]/gi,"");

use this js in oninput of the input field

2024-07-16 17-36-51
Shradha Rawlani

Hi,

Try to use input mask forge component or regex

Regards

Shradha

UserImage.jpg
Lavanya A

Hi,
As praveen Suggested use JS to prevent the alphabets, in addition to that restrict a default key "e" to remove that add JS
  var e = window.event || e;  var key = e.keyCode;   if (key == 69) {     e.preventDefault();      return false;   }  

2023-09-19 19-26-44
Josias Ramos Pinto

Validation with Regular Expression

If you want to be even more restrictive (e.g., allowing only digits), you can use an event to validate the user's input. 
A common method is to use the OnChange or OnInput event to trigger an action.

Add a Client Action to the input widget and use a regular expression to validate the input: 

if (!/^\d*$/.test($parameters.InputValue)) {    $parameters.InputValue = $parameters.InputValue.replace(/\D/g, '');
}

This removes any non-numeric characters that the user has entered.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.