My custom validation does not work as it should - please help me

Hi everyone, actually I know little of coding and whatever codes I have I managed to write them after scratching my head reading the articles in the forum. So any help will be very much appreciated.
Actually I have an input field in a form (‘#input1’)which i am validating using oncustomvalidation based on another input (‘#input2’) which is a number that is obtained from a dataset collection on the same page. I want (‘#input1’) to be less than (‘#input2’) otherwise it needs to be rejected and an error message to display. I am using the code below which appears to work sometimes but fails in many cases. For instance if (‘#input2’) value is 12 then 10, 11 and 12 are accepted but 1-9 are not accepted. Can anyone please help me out here

$w(" #input1 ").onCustomValidation( (value, reject) => {
let Amount = $w(’ #input2 ').value;
if ( value > Amount ) {
reject(“Value must be less than .”);
}
} );

You can see more about custom validation here.
https://www.wix.com/corvid/example/custom-validations
https://support.wix.com/en/article/working-with-user-input-validation-in-the-settings-panel
https://support.wix.com/en/article/corvid-about-validating-user-input-with-code
https://www.wix.com/corvid/reference/$w.ValidatableMixin.html
https://www.wix.com/corvid/reference/$w.TextInput.html

Thanks GOS for the quick reply but after going through all these articles only I managed to write the above code. But dont know whats wrong the code is not working as expected maybe some bug or problem with my code. Help is greatly appreciated

Please someone look into my code and help me as to why it is not working properly, help is highly appreciated. Thank you

Have a look at this page here and you will see how to do it.
https://givemeawhisky.wixsite.com/mysite-19/numbertest

It is setup to get the current number from the dataset field, which is shown in the black box which is setup as read only.

The user enters their number input in the top box and if the number they enter is more than the dataset field or less than 0, then the input is rejected as it needs to be less than the supplied number but more than zero.

You will also need to change your dataset permissions so they are setup for anyone.

@ GOS Thanks a lot for the reply, with your help I was finally able to find out the issue and resolve it.