How do you put validation in a simple form?

Hi! I was successfully able to make a simple form that when submitted adds an entry to the database, very similar to the “Add Object with API” mission.

I just want to take it a step further, by limiting what the user could input:

  1. Say, I want the zip code to just accept numbers, and should be 4 digits (not more, not less); phone numbers should be 11 digits, etc.
  2. A drop-down that is dependent on another drop-down, similar to a “STATE” dropbox, then the next would be “CITY”, where CITY dropbox would only contain cities on the selected state. (I already have a table with the state and city)

I want the form to reject the whole submission if one of the fields does not satisfy the set validations.
(Real-time validation would be cool! But if it’s too complicated, I’m okay with the validation happening upon clicking “Submit”)

Could someone help me? Or maybe redirect me to a link in the forum or a YouTube video that could help me? Thanks so much!

Hi @Erik1,

Welcome to the comminity! :slightly_smiling_face:

  1. Say, I want the zip code to just accept numbers, and should be 4 digits (not more, not less); phone numbers should be 11 digits, etc.

You can set the required validator on the Data → Required table → Table Editor tab. A validator can be added to almost any data type column.

  1. A drop-down that is dependent on another drop-down, similar to a “STATE” dropbox, then the next would be “CITY”, where CITY dropbox would only contain cities on the selected state. (I already have a table with the state and city)

In order to get the described result, you need to use data binding. We have created a small example of how this can be achieved:




How it works: When a name value is selected in the first field. The drop-down list in field 2 contains the names. When age is selected in field 1, field 2 respectively contains age values.
I hope this helps you.

There are many tutorial videos on our youtube channel. I can recommend you to check them out. https://www.youtube.com/@Backendless

Regards,
Marina