Jump to content

how can i use a filter in function


arden

Recommended Posts

can i put 2 functions in a code?ie.i got this:

function isValidEmail($email=' '){return preg_match("/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix",$email);}

can i put another function for filtering AGE?..what is the code i need?..thx...

Link to comment
Share on other sites

This should work:

function isValidAge ($age) {   $re = '/^\d{1,3}$/';   return $age != "0" && preg_match($re, $age);}

This assumes that $age is a string. It will return false if $age is "" or "0", if there are more than 3 characters, or if any of the characters are not digits.

Link to comment
Share on other sites

FWIW, a professional should be able to write excellent code using only Notepad. It's the programmers who can't work without Dreamweaver that I worry about. :)

Link to comment
Share on other sites

I think arden was asking if he can principally (in theory if you will) put two functions in a file... and to answer that, in the words of Obama - Yes, we can!You can put as much functions as you want on a PHP page. However, as you should've realized by now, code within a function is only executed when you call the function, i.e. when later in your code you have something like (to follow your example):

isValidEmail('myemail@example.com');

or (more likely for this particular function):

if (isValidEmail('myemail@example.com')) {

Link to comment
Share on other sites

I think I just felt like testing a regex. In (almost) the words of Robert Duvall, "I love the smell of regex in the morning." Of course, it's only morning where I am. :)

Link to comment
Share on other sites

thanks for all your help guys..hehe.. yes we can.. :) now my new problem is UPLOADING an image..i got no idea about this one..i saw the FILE UPLOAD in php.. as of now i got no idea how to use it..

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...