Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Allow only numbers and symbols in a field

Questions related to using nuBuilder Forte.
Post Reply
kknm
Posts: 370
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Allow only numbers and symbols in a field

Post by kknm »

How to allow entering only numbers and certain characters in a table field :
+
-
=
kev1n
nuBuilder Team
Posts: 4497
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 511 times
Contact:

Re: Allow only numbers and symbols in a field

Post by kev1n »

Hi,

Do you want the validation to happen in the browser using JavaScript?
kknm
Posts: 370
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Allow only numbers and symbols in a field

Post by kknm »

I would like to have a field restriction on alphabetic characters
kev1n
nuBuilder Team
Posts: 4497
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 511 times
Contact:

Re: Allow only numbers and symbols in a field

Post by kev1n »

alphabetic characters means letters A–Z and a–z, but initially you wrote "only numbers and certain characters".
kknm
Posts: 370
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Allow only numbers and symbols in a field

Post by kknm »

For starters, you can only ban letters
kev1n
nuBuilder Team
Posts: 4497
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 511 times
Contact:

Re: Allow only numbers and symbols in a field

Post 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.
kknm
Posts: 370
Joined: Sat Apr 11, 2020 12:03 am
Has thanked: 3 times
Been thanked: 4 times
Contact:

Re: Allow only numbers and symbols in a field

Post by kknm »

Brilliantly !! Thank you !
Post Reply