Jump to content


Photo

Validation


  • Please log in to reply
3 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 14 March 2006 - 03:13 PM

Hi, i am going through a book i purchased and this is some of the code in the book.
The code has not been explained properly in the book and i don't understand it fully.
I know that it is validating the values (i.e the first line i have shown below is for
validating the name of a person.) If someone could please explain what the validation is
doing (i.e what does !ereg mean? and is the first line simply checking to see if the value
is between letters a-z and less than 50 in length?). If someone could explain the lines
i would be greatfull.

if (!ereg("^[A-Za-z' -]{1,50}$",$value))

if(!ereg("^.+@.+\\..+$",$value))

if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value))

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 14 March 2006 - 05:57 PM

validating is checking to make sure it is right (useing the right characters)
if (!ereg("^[A-Za-z' -]{1,50}$",$value))

if(!ereg("^.+@.+\\..+$",$value))

if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value))

and this is the code they are validating with so if there input doesn't match any of the characters listed the form will return false and they will get an error message something like your name contains invalid characters.

i dont know if that is what you are looking for but i hope that helps

The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 14 March 2006 - 06:05 PM

here's the basic idea of what they're doing:

if (!ereg("^[A-Za-z' -]{1,50}$",$value))
-this line is simply saying that the $value must be between 1 and 50 characters and can only contain letters, apostrophes, spaces and hyphens

if(!ereg("^.+@.+\\..+$",$value))
-this line looks like a very basic email validation. it's simply checking to make sure you have at least one character followed by an '@' symbol, then at least one more character followed by a period, and then finished off by at least one more character. this is a really sloppy email validator, though, because i could type in ".@..." and it would match. a much better one would be:
if (!preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i", $value))
  // invalid email address

and finally:
if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value))
-this is simply making sure that $value is a 16 digit number starting with a 5. seems to be a rudamentary credit card validation.

hope this helps


You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 14 March 2006 - 06:06 PM


what ereg does and this means ! not


To detect non-alphanumeric characters (for new username/password validation, for instance):
if(ereg('[^A-Za-z0-9]', $username)){
 echo "Usernames must contain only letters and numbers.";
}else{
 echo "$username is a valid username.";
} 

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users