Priyanka Patel
Posts: 0
Joined: Sat Aug 17, 2013 5:41 am

Input type as numbers only.

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?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Input type as numbers only.

Hello!

Please post the code you tried.

Priyanka Patel
Posts: 0
Joined: Sat Aug 17, 2013 5:41 am

Input type as numbers only.

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Input type as numbers only.

Looking for solution..

Priyanka Patel
Posts: 0
Joined: Sat Aug 17, 2013 5:41 am

Input type as numbers only.

Any luck?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Input type as numbers only.

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

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

Priyanka Patel
Posts: 0
Joined: Sat Aug 17, 2013 5:41 am

Input type as numbers only.

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Input type as numbers only.

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

Return to “Issues”