Limit Form Input TYPE=TEXT to Numbers Only?

madmatt

Bow Down to the King
Political User
Joined
Apr 5, 2002
Messages
13,312
#1
You would think they would have a type=numbers by now...

Does anyone know a way (without using JavaScript?) to limit a form input to numbers only?

Thank you.
 

SPeedY_B

I may actually be insane.
Joined
Mar 31, 2002
Messages
15,800
#2
There's no way that I know of, other than to get the inputted value when submitted and check if that is numbers only. For example, with PHP, you could use is_numeric();
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#3
you could use ajax to call a php validation function on the server side, then also check the values when the form is submitted using the same php function. this is the method I tend to use if I want any client side validation, though you said no javascript, as it means my validation code is only in one place and isnt duplicated in two places. Though it does mean more traffic between the client and the server.

you can use is_numeric or ctype_isdigit or a regular expression
 

madmatt

Bow Down to the King
Political User
Joined
Apr 5, 2002
Messages
13,312
#4
Geffy, do you have any good resources for AJAX and form validation? I don't mind JavaScript but I hate annoying popup dialogs ("Fix these errors and press submit again." -- OK button).

Thank you.
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
#5
Ruby on Rails and model validations :D

Or AjaxCore might do what you need. It lets you pretty easily bind php functions to HTML objects. So you could "onchange" send the field data for checking and then set the contents of a div or span or border the field in red to indicate the incorrect status of the field
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,979
Messages
673,325
Members
89,020
Latest member
Amanda99