There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 boot bsod computer cpu crash css dell desktop driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware help please hijackthis hjt hjt log install internet internet explorer itunes javascript keyboard lan laptop log malware monitor network networking outlook outlook 2003 outlook express password php popups problem router seo slow sound sp3 spyware startup trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless youtube
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
form validation using php


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
sudhakararaog's Avatar
Computer Specs
Member with 64 posts.
 
Join Date: Sep 2007
Experience: Intermediate
14-May-2008, 02:09 AM #1
form validation using php
hi

i need to validate a field in a form where a user enters their lodgement number as part of a registration form. this lodgement number can have letters, numbers, spaces and special characters. i do not know exactly what those special characters are, so do i have to define the type of special characters and validate accordingly.

presently my php code for validating the lodgement number is

$lodgementtf = $_POST["lodgementtf"];

if($lodgementtf == "" || !preg_match("/^[a-zA-Z0-9_ <]+$/", $lodgementtf) )
{
echo "display error message":
}


i also have another way of validating

if($lodgementnumber == "" || !preg_match("/^[a-zA-Z0-9_ !-@£$%^&*()]+$/", $lodgementnumber) )

does this mean that the special characters can only be = a space AND _!-@£$%^&*() and no other special characters.

please advice.

thanks.
TroyTime's Avatar
Computer Specs
Junior Member with 12 posts.
 
Join Date: Apr 2008
Experience: programmer for 10 years, but new to vista
14-May-2008, 04:16 PM #2
it doesn't make much sense to string validate a field that can have numbers letters spaces AND special characters

but then again, it doesn't make much sense for any "number" to have letters numbers spaces and special characters...
awatson's Avatar
Member with 66 posts.
 
Join Date: Jan 2008
Experience: Advanced
14-May-2008, 04:47 PM #3
Well, it could make sense in some situations - i.e. like an apartment number (4F or something). But if the range of characters is too wide, it probably does make more sense to check for other things, such as number of characters.
Mudley's Avatar
Computer Specs
Member with 99 posts.
 
Join Date: Apr 2008
Experience: Advanced
14-May-2008, 11:31 PM #4
yeah it doesn't make much sense to validate such a fubared string.

if you need to verify that its valid, trap it for harmfull data (xss, sql, javascript, etc) and compare it with your database

regular expressions are great, but they're slow
don't use them here unless you're matching a specific pattern (like 4 numbers followed by 1 or 2 letters followed by another three numbers followed by a ! or a @ or a $ and then followed by another 2 numbers)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:11 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.