Jump to content


limiting input fields


4 replies to this topic

#1 tones

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 10 March 2008 - 05:57 AM

OK, this probably sounds real basic, and should anyone have the solution, become apparent on how basic it is, but damn my minds blank.

What i need is, to be able to limit a text field to 8 characters, and only allow it to be numerical. as the input field is for posting a member ID

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 10 March 2008 - 07:13 PM

<input type="text" name="test" value="123456789" maxlength="8">

Or to be 100% about it's length:
strlen() (of course, substr() could "cut out" additional characters).
Then for the number part: is_numeric()

#3 tones

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 11 March 2008 - 05:55 AM

Thanks i got it, i used eregi to check it was numerical and strlen for the length.

Edited by tones, 11 March 2008 - 05:56 AM.


#4 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 14 March 2008 - 10:04 PM

learn how to use substr() and that will be your new best friend! :)

Edited by SpatialVisionary, 14 March 2008 - 10:05 PM.


#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 15 March 2008 - 12:41 AM

Well, when taking a member id, the idea is not to truncate any erroneous characters. It is to make sure it fits certain parameters, or alert the user to their having provided incorrect information.

Though, i still recommend is_numeric() over eregi (numbers really only have one case, and are usually only numbers...).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users