Jump to content


Photo

PHP form validation


  • Please log in to reply
3 replies to this topic

#1 Mateobus

Mateobus
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 31 July 2006 - 10:49 PM

I am trying to write a php function that validates a username and password. To keep things simple i want to allow only letters and numbers upper and lower case allowed.  Is there a good function for this?

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 31 July 2006 - 10:54 PM

If you want to define what characters to allow/disallow, look into regular expressions.
PHP Ninja

#3 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 31 July 2006 - 10:57 PM

This isn't perfect but...

if (preg_match('/^[0-9a-zA-Z]+$/i', $_POST['FieldName'])) {
  echo 'matches';
} else {
  echo 'no match';
}
I'm considered good looking in some countries

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 09:39 AM

This isn't perfect but...

if (preg_match('/^[0-9a-zA-Z]+$/i', $_POST['FieldName'])) {
  echo 'matches';
} else {
  echo 'no match';
}

if you have the i modifier, you dont need the a-z bit in the expression gijew. So the expression can be just:
/^[0-9A-Z]+$/i





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users