Page 1 of 1

Input type as numbers only.

Posted: Sat Aug 31, 2013 9:20 am
by Priyanka Patel

Hi there,

Currently, I have an input field of type number. I want to do a check on the input field to
a: give alert if the user inputs string.
b: restrict the numbers that user can input to between 0 and 30.

Not sure how I could use JS to do this.
Regular expressions?


Input type as numbers only.

Posted: Sat Aug 31, 2013 9:23 am
by Alena Prykhodko

Hello!

Please post the code you tried.


Input type as numbers only.

Posted: Sat Aug 31, 2013 9:31 am
by Priyanka Patel

var temp2 = Appery('numberInput').val();
var participant_number = Appery.parseInt(temp2, 10);
if(participant_number < 0 && participant_number 30){
alert("Invalid participant number. Please try again.");
}else{
Appery.navigateTo('HomeScreen', {});
}

I figured that if the input is number, then parse Int will not work.
However I get an error message in the console that says,

Post method did not succeed. 400 bad request


Input type as numbers only.

Posted: Sat Aug 31, 2013 11:08 am
by Alena Prykhodko

Looking for solution..


Input type as numbers only.

Posted: Sat Aug 31, 2013 1:08 pm
by Priyanka Patel

Any luck?


Input type as numbers only.

Posted: Sat Aug 31, 2013 2:28 pm
by maxkatz

parseInt(..) should work, https://developer.mozilla.org/en-US/d...

Post method did not succeed. 400 bad request -- looks like a REST request error.


Input type as numbers only.

Posted: Sat Aug 31, 2013 3:11 pm
by Priyanka Patel

Well done, yes it is a REST error as the button also has an associated REST service associated it.

Still remains that the above code, does not give an alert as it should when a string is entered.


Input type as numbers only.

Posted: Sat Aug 31, 2013 5:26 pm
by maxkatz

Please debug your code. The if-statement that you have is not correct.