954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

validating input

hi
how to validate inputs in php.please send some same code for email and numbers...
thanks,
lydia

lydia21
Junior Poster
183 posts since Nov 2007
Reputation Points: 19
Solved Threads: 5
 

validating in php really isn't that hard. i have been using this function for a while. i don't know if it is the best way but it works for me.

function check($fieldname)
{
  if(!preg_match("/[^a-zA-Z0-9\.\-\Ä\ä\Ö\ö\Ü\ü\,\
   ]+$/s",$fieldname)) {
    return TRUE;
}
else {
    return FALSE;
}
}
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

for numbers,you can use this function:

function checknumber($fieldname)
{

if (is_numeric($fieldname)==TRUE)//if it is a number..
{
return TRUE;
}
else
{
return FALSE;
}

}
ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

for numbers,you can use this function:

function checknumber($fieldname)
{

if (is_numeric($fieldname)==TRUE)//if it is a number..
{
return TRUE;
}
else
{
return FALSE;
}

}


hi
this is not working for me...

lydia21
Junior Poster
183 posts since Nov 2007
Reputation Points: 19
Solved Threads: 5
 

What do you mean it does not work?

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

If it doesn't work, you're not doing it right. Learn basic PHP skills before you post.

@ryan_vietnow: you might want to simplify that; the function returns what is_numeric does on it's own.
Just do something like

$x = $_GET['foo']; echo is_numeric($x);


@lydia21: you posted this same thread 3+ times...

hacker9801
Junior Poster
130 posts since Aug 2007
Reputation Points: 59
Solved Threads: 16
 

ya the code the which u have send me is not working

lydia21
Junior Poster
183 posts since Nov 2007
Reputation Points: 19
Solved Threads: 5
 

ya the code which u have send me is not working

lydia21
Junior Poster
183 posts since Nov 2007
Reputation Points: 19
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You