SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limit form input to numbers?

    Hello,

    How can I make sure that users enter ONLY numbers in certain fields? The range of numbers is too wide to use a drop-down. I use these numbers in calculations afterwards so I don't want the user to enter "one" instead of "1" etc...

    Thank you!

    Julie

  2. #2
    SitePoint Evangelist stef25's Avatar
    Join Date
    Nov 2004
    Location
    belgium
    Posts
    465
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can either do this on the server side with php or whatever other language you are using. or even better, use javascript and regular expressions on the client side. regexp is not that easy and you also need to decide how you're going to tell the users they entered something wrong. so to answer your question, google "regexp form validation"
    I need someone to protect me from
    all the measures they take in order to protect me

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, a regular expression for validating numbers is quite easy:
    Code:
    ^\d+$
    Using JavaScript, you may also want to add an event listener that prevents the user from typing anything but digits. Post such questions in the JavaScript forum.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •