Jump to content

Help understanding entry validation.


Drewdle

Recommended Posts

I'd like some help understanding how to use validation for form field characters please!

 

if(!preg_match("/^[a-zA-Z]+$/",$_POST['fname']))
{
echo "Invalid Entry";
}

 

Now, where do I specify what characters to check? Is it this part:

 

("/^[a-zA-Z]+$/",$_POST['fname'])

 

How would I add other things? I believe that allows upper and lower case letters only, how would I add things like '@' '-' '_' etc etc...would I just add them to the list inside the square brackets or is it a new set of brackets?... What about numbers? Would it be "/[0-9]/" ?

 

Also, can I swap $_POST['fname'] with just a plain variable ($fname)?.

 

(oh and does it need the '/' inside each quote?)

 

Thanks!

 

OH and also! if I was to check several fields, and if all is ok execute a script would I need to have elseif/else statements of could I have a new if statement for each and then just run the script below it?

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/225691-help-understanding-entry-validation/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.