2 Replies - 3164 Views - Last Post: 07 August 2009 - 12:34 PM Rate Topic: -----

#1 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

validate username, only allow letters & numbers

Post icon  Posted 07 August 2009 - 12:01 PM

hello.

i am currently using this script for my username input check, but i realized that it does not stop spaces or characters other than numbers or text.

does anyone have a username validation w/o using javascript that they would recommend to me?

thank you.

$_POST['username'] = trim($_POST['username']);
  if (empty($_POST['username'])) {
	  $error['userinfo'] = 'Please make sure you have filled in an username.';
  }
  // Check the username for length
  $_POST['username'] = trim($_POST['username']);
  if (strlen($_POST['username']) < 8) {
	  $error['length'] = 'Please select a username that contains at least 8 characters';
  }



Is This A Good Question/Topic? 0
  • +

Replies To: validate username, only allow letters & numbers

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: validate username, only allow letters & numbers

Posted 07 August 2009 - 12:09 PM

If you want to allow only numbers and alphabetic letters you could use the ctype_alnum() function. You should also check up on using regular expressions! :)
Was This Post Helpful? 1
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,003
  • Joined: 08-August 08

Re: validate username, only allow letters & numbers

Posted 07 August 2009 - 12:34 PM

There's also str_replace() in case you want to use lists of disapproved words and their replacements.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1