Number only in a jquery text box

How do I get to limit text to only numbers? Easy to do in VB.Net but jquery does not use an “e” parameter. Thanks for any assistance or a sample

Bob Briscoe

That’s an html setting

<input type=“number” ...

Check the docs. See inputType.

In VB.Net you would do something like this:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

'97 - 122 = Ascii codes for simple letters

'65 - 90 = Ascii codes for capital letters

'48 - 57 = Ascii codes for numbers

If Asc(e.KeyChar) <> 8 Then

If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then

e.Handled = True

End If

The JQuery text box does not have an input type as a property. I’m guessing you would put some code in the Style property? Can you tell me if this is correct and what code would I put in there?


Bob Briscoe

AppStudio has a nice translator to change VB-style BASIC to JavaScript, so your code is pretty much the same.

However, the controls are based on HTML elements and will have different properties and appearance than Windows-style controls.

In this case, you’ll need to use the documented properties from the Wiki, not the way VB used to do it.

I do not need a translator, I just need to know where to put the code to set the input to a text box to numbers only. I also would like to see an example if one is available.


Bob Briscoe

Did you check the docs? inputType is one of the control’s properties.

Please note that the jQuery Mobile controls are no longer supported. The group which maintains them abandoned them years ago.

Hi Phil,
My Properties for jquery textbox do not have the input type. There must be a way to set numbers only. Attached is my properties using the latest version of NSB

Bob Briscoe

Can you post a screenshot of the Project Explorer, with txtZipCode showing?

Yes, here it is

As you can see there is no Input type.

Bob Briscoe

That’s the same as last time - it’s the Properties window. Can you send the Project Explorer window?

Hi Phil,
Here is the project explorer. It does not have much information.

On a second note, do you know in what directory I should place a php file?


Bob Briscoe

Thanks for posting this. Notice the element icon in the Project Explorer is “Ta”, not “Tx”?

It’s a Textarea, not a Textbox. Textareas are meant for multiline text input, and do not have an inputType property.

You probably want to use a Textbox, since this is a single line input field.

Ah HA! No wonder I was having problems. Thanks very much.

Bob Briscoe

Excellent diagnosis George!

I see jqm and bs4 controls in the same project. I thought AppStudio couldn’t A: open jqm controls and B: couldn’t use them together.

jQM uses an obsolete version of jQuery. This version has know security vulnerabilities. BS4 used the latest jQuery, so that’s not a problem.

The styling of jQM doesn’t just affect jQM controls. It will leak over and screw up your BS4 controls.

We’ve recommended for several years that everyone update their project to no longer use jQM. The migration tool can be a big help.


I did not realize using JQuery Mobile would screw up the logic in other controls. Specifically you seem to be suggesting do not use JQuery at all. OK, I am in the process of changing my app to get rid of all the text boxes but it seems the only control available for a text box is the bootstrap input box with a 0 length in the header section. Is this correct? Are there any controls that safari will not process? Seems like the bootstrap input will allow only numbers but does not seem to limit the number of characters for example in a zip code input. The capital’s only property does not seem to work in safari. It’s OK in firefox. Maybe that’s because I have not cleaned out all the old Jquery text boxes.

Bob Briscoe

jQuery is fine. It’s jQuery Mobile that the problem. (Yes, they are completely different things).

Yes, the Bootstrap Input control is the replacement. All Bootstrap controls are supported by all browsers, including Safari.