OriginalSunny Posted March 14, 2006 Share Posted March 14, 2006 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 forvalidating the name of a person.) If someone could please explain what the validation isdoing (i.e what does !ereg mean? and is the first line simply checking to see if the valueis between letters a-z and less than 50 in length?). If someone could explain the linesi would be greatfull. if (!ereg("^[A-Za-z' -]{1,50}$",$value)) if(!ereg("^.+@.+\\..+$",$value)) if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value)) Quote Link to comment https://forums.phpfreaks.com/topic/4931-validation/ Share on other sites More sharing options...
shortj75 Posted March 14, 2006 Share Posted March 14, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4931-validation/#findComment-17443 Share on other sites More sharing options...
obsidian Posted March 14, 2006 Share Posted March 14, 2006 here's the basic idea of what they're doing:[b]if (!ereg("^[A-Za-z' -]{1,50}$",$value))[/b]-this line is simply saying that the $value must be between 1 and 50 characters and can only contain letters, apostrophes, spaces and hyphens[b]if(!ereg("^.+@.+\\..+$",$value))[/b]-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:[code]if (!preg_match("|^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i", $value)) // invalid email address[/code]and finally:[b]if(!ereg("^[5]{1,1}[0-9]{15,15}$",$value))[/b]-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 Quote Link to comment https://forums.phpfreaks.com/topic/4931-validation/#findComment-17446 Share on other sites More sharing options...
redarrow Posted March 14, 2006 Share Posted March 14, 2006 what ereg does and this means ! notTo detect non-alphanumeric characters (for new username/password validation, for instance):[code]if(ereg('[^A-Za-z0-9]', $username)){ echo "Usernames must contain only letters and numbers.";}else{ echo "$username is a valid username.";} [/code] Quote Link to comment https://forums.phpfreaks.com/topic/4931-validation/#findComment-17447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.