User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,853 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,387 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

Help on form validation requested.

Join Date: Jul 2007
Posts: 110
Reputation: Taffd is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
Taffd Taffd is offline Offline
Junior Poster

Help on form validation requested.

  #1  
Nov 17th, 2007
Hello everbody,
Despite some serious googling, viewing previous posts here and consulting the php manual, I am still unable to validate my user input.
If I can get one simple form to validate, I will be able to adapt the script accordingly to any other, so any help you can give will be much appreciated.

Problem.
I have a comments page. I want the user to be able to submit a comment, which if it validates will then be stored in a database, called and displayed on the 'comments' page.

At present, with no validation attempted, everything works fine.
What I want to do is make sure the user enters only text and punctuation.

Examples I've seen use preg_match. The php manual, however states that as soon as a match is found, checking of the 'subject' string stops and preg_match_all should be used. Therefore if I used
if(preg_match("/[^a-zA-Z0-9\.\  ]+$/",$field_name))
return TRUE;
  else
    return FALSE;
then a question mark ? at the end of a sentence, would still validate.

I have also seen
if(!preg_match("/[^a-zA-Z0-9\.\  ]+$/",$field_name))
return TRUE;
  else
    return FALSE;
This would seem to say 'If the regex does not match '$field_name', return true.

I don't want to put too much in this first post, so tell me, am I correct so far.
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 8:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC