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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.