Limit Form Input TYPE=TEXT to Numbers Only?

  • Thread starter madmatt
  • https://www.osnn.net/admin.php?templates/thread_view.1970/delete&_xfRedirect=https%3A%2F%2Fwww.osnn.net%2Fadmin.php%3Ftemplates%2Foutdated Start date

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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
31 Mar 2002
Messages
15,806
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
18 Mar 2002
Messages
7,805
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

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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
18 Mar 2002
Messages
7,805
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 forum posts

Latest profile posts

Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,002
Messages
673,449
Members
5,596
Latest member
Joshua Liansky