Page 1 of 1

Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 7:37 am
by kknm
How to allow entering only numbers and certain characters in a table field :
+
-
=

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 7:43 am
by kev1n
Hi,

Do you want the validation to happen in the browser using JavaScript?

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 8:34 am
by kknm
I would like to have a field restriction on alphabetic characters

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 8:40 am
by kev1n
alphabetic characters means letters A–Z and a–z, but initially you wrote "only numbers and certain characters".

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 8:43 am
by kknm
For starters, you can only ban letters

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 8:47 am
by kev1n
For example, to allow only digits and the characters +, -, =:
Add an oninput event to your input object and call validateInput(this);.
In the form’s Custom Code, declare the function:

Code: Select all

function validateInput(input) {
    // Allow digits, +, -, =
    let regex = /^(\d|[+\-=])*$/;
    if (!regex.test(input.value)) {
        input.value = input.value.slice(0, -1); // remove last invalid character
    }
}
You can use AI to help modify the regex if you need to allow additional characters or other patterns.

Re: Allow only numbers and symbols in a field

Posted: Mon Sep 22, 2025 9:06 am
by kknm
Brilliantly !! Thank you !