# Setting input limit

**URL:** <https://forum.wixstudio.com/t/setting-input-limit/28002>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [July 14, 2020, 4:17pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002 "2020-07-14T16:17:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![paiysurv](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paiysurv/32/3707_2.png) [@paiysurv](https://forum.wixstudio.com/u/paiysurv)\
**Post date:** [July 14, 2020, 4:17pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/1 "2020-07-14T16:17:19Z")

</div>

Is there a way i can set an input limit to a certain value with js? The other way of setting limit in the input settings is not applicable because i would like each user to have his own limit.  
I have tried using a cache collection in another database which will compare the input element with a the cache vale but seems it is not working. Here is the code and I would appreciate any help.

```javascript

export function button300_click(event) { 
 let cache= $w('#dataset25').getCurrentItem().cache;
 let sumHrs= $w('#dataset24').getCurrentItem().pnumber;
 let withdraw=$w('#input9').value
 if(cache<withdraw){
        $w('#button300').hide()
        $w('#text21').text="You have insufficient funds to withdraw "+$w('#input9').value;
    }
 else{
         $w("#dataset21").onReady(() => {
            $w('#dataset21').setFieldValue('phoneNumber', sumHrs)
            $w('#dataset21').setFieldValue('status', "Pending")
            $w('#dataset21').save()
        })
    }}

```

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 14, 2020, 4:21pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/2 "2020-07-14T16:21:31Z")

</div>

Hello pay.surv,  
take a look at this example…  
[https://russian-dima.wixsite.com/meinewebsite/blank-17](https://russian-dima.wixsite.com/meinewebsite/blank-17)  
Perhaps it is, what you are looking for.

---

<div class="post-metadata">

**Author:** ![paiysurv](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paiysurv/32/3707_2.png) [@paiysurv](https://forum.wixstudio.com/u/paiysurv)\
**Post date:** [July 14, 2020, 4:38pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/3 "2020-07-14T16:38:54Z")

</div>

Hello Russian dima, i have openen your code and have realized you have created for character limit. My issue is slightly different since am trying to set a limit for numerical input.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 14, 2020, 4:51pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/4 "2020-07-14T16:51:14Z")

</div>

Give some examples for numerical limits?

You can put into a inputfield some values. These can be NUMBERs, STRINGS and a few more, but you can manipulate the value.lenghth of all of them, right?

So if i would say, the numerical input-limit is [999] \<Number, so you say, that if the length of the value \>= 3 —\> do something, if not, do somthing else.

Isn’t it a limitation? You would limit your input to 3-characters. With this 3-characters your max NUMBER is —\> 999, et voila, you have your limitation.

Of course it’s not a complete limitation, but you can expand the code and modify it much more.

But perhaps i did not understand what you want 😁

---

<div class="post-metadata">

**Author:** ![paiysurv](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paiysurv/32/3707_2.png) [@paiysurv](https://forum.wixstudio.com/u/paiysurv)\
**Post date:** [July 14, 2020, 5:11pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/5 "2020-07-14T17:11:55Z")

</div>

Your example is used to set the number of characters in an input field. But my issue is how to set a limit value. For instance if i want input to be 4, all values from 1 to 4 will be accepted e.g  
000001,  
0.00099 ,  
2.938,  
3.9999999  
For your case

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 14, 2020, 5:24pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/6 "2020-07-14T17:24:56Z")

</div>

Now i know what you mean.

Then try to work with something like —\> parseFloat, or round-methods.

Do not know if this example fits, but it do what you are searching for, on my opinion.

[https://russian-dima.wixsite.com/meinewebsite/blank](https://russian-dima.wixsite.com/meinewebsite/blank)

Use the lower input and type in your example-numbers with “.” and then with “,” as separator (and do not forget to activate the “parseFloat”-function 😁

If you just work with —\> " , " this will work.  
You should think about, how to EXCLUDE —\> the point " . "

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 14, 2020, 5:27pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/7 "2020-07-14T17:27:42Z")

</div>

So now you should have enough tools, to achieve your aim.  
Here you have some more input…  
[https://www.w3schools.com/js/js\_number\_methods.asp](https://www.w3schools.com/js/js_number_methods.asp)

---

<div class="post-metadata">

**Author:** ![paiysurv](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paiysurv/32/3707_2.png) [@paiysurv](https://forum.wixstudio.com/u/paiysurv)\
**Post date:** [July 14, 2020, 6:19pm UTC](https://forum.wixstudio.com/t/setting-input-limit/28002/8 "2020-07-14T18:19:35Z")

</div>

@russian.dima You seem to be suggesting a regex to regulate the input value which will allow for whole numbers and decimals. That is no what am looking for for actually. Please go back to my original post and follow it through.
