iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old March 9th, 2008, 09:23 AM   #1
New Member
 

Join Date: Dec 2007
Location: auckland
Age: 34
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 sudhakararaog is on a distinguished road
VERY IMPORTANT question about validation using php

i am using php in order to validate a form where users register. please help me to solve the following validations.

1. name can have spaces. ex= john smith
presently the validation i am using is if( $fname == "" || !eregi("^[a-zA-Z_]+$", $fname) )
i need the syntax which would accept a-zA-Z WITH A SPACE IN BETWEEN NAMES ex= john smith

2. text can have spaces and special characters ex= ref 100/abcd
presently the validation i am using is if( $depositnumber == "" || !eregi("^[a-zA-Z0-9_]+$", $depositnumber) )
i need the syntax which would accept a-zA-Z0-9 WITH A SPACE IN BETWEEN AND SPECIAL CHARACTERS ex= ref 100/abcd

3. spaces in numbers. ex= 123 4567
presently the validation i am using is if( $phonenumber == "" || !eregi("^[0-9]+$", $phonenumber) )
i need the syntax which would accept 0-9 WITH A SPACE IN BETWEEN
ex= 123 4567

4. in case of [a-zA-Z0-9_] if i remove the "_" after 9 will it have a negative impact or is this a syntax due to which i
should i leave the "_" as part of [a-zA-Z0-9_]

5. using stripslashes() function
due to the above validation there is no way a user can enter special characters which could lead to sql injection. inspite of
this should i still use stripslashes to be on the safe side.

please provide the exact syntax for the above validations to works as specified for different scenarios.

thanks.
sudhakararaog is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 9th, 2008, 11:44 AM   #2
Reputable Member
 

Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 RohanShenoy is on a distinguished road
Re: VERY IMPORTANT question about validation using php

http://www.sitepoint.com/article/reg...ressions-php/2
The syntax reference given on this page should help you.
and we could have better thread titles next time plz!

Last edited by RohanShenoy; March 9th, 2008 at 11:47 AM..
RohanShenoy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 9th, 2008, 12:29 PM   #3
Highly Reputable Member
 
masonbarge's Avatar
 

Join Date: Jan 2006
Location: Atlanta GA
Posts: 640
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 masonbarge will become famous soon enough
Re: VERY IMPORTANT question about validation using php

I'm not a regex expert by any means and I use PCRE, so caveat emptor.

Quote:
Originally Posted by sudhakararaog View Post
i am using php in order to validate a form where users register. please help me to solve the following validations.

1. name can have spaces. ex= john smith
presently the validation i am using is if( $fname == "" || !eregi("^[a-zA-Z_]+$", $fname) )
i need the syntax which would accept a-zA-Z WITH A SPACE IN BETWEEN NAMES ex= john smith
In PCRE you can use the x modifier to ignore spacing in the entire expression. ("/^[a-zA-Z_]+$/x")

Your description "name can have spaces" is inadequate; you'd be a lot closer to a solution with a more precise description. If you just want to allow spaces anywhere in the string, use the "x" modifier (if POSIX allows it) or just put a space in the brackets: ("/^[a-zA-Z_ ]+$/x")

Quote:
2. text can have spaces and special characters ex= ref 100/abcd
presently the validation i am using is if( $depositnumber == "" || !eregi("^[a-zA-Z0-9_]+$", $depositnumber) )
i need the syntax which would accept a-zA-Z0-9 WITH A SPACE IN BETWEEN AND SPECIAL CHARACTERS ex= ref 100/abcd
I'm having trouble understanding what you want here - maybe somebody else will understand it. What "special characters"? If you're allowing all special characters, why do you need regex? If there are specific characters you want to allow, just put them inside the brackets.

Quote:
3. spaces in numbers. ex= 123 4567
presently the validation i am using is if( $phonenumber == "" || !eregi("^[0-9]+$", $phonenumber) )
i need the syntax which would accept 0-9 WITH A SPACE IN BETWEEN
ex= 123 4567
Actually, I would advise you not to do this at all, but to use three fields for a US-style telephone number.

However, a simple PCRE regex for a ten-digit US telephone number using spaces as the seperator would be
"/^[2-9][0-9]{2} [2-9][0-9]{2} [0-9]{4}$/".
To match a space, just put a space in the expression; it's a character just like any other.

Quote:
4. in case of [a-zA-Z0-9_] if i remove the "_" after 9 will it have a negative impact or is this a syntax due to which i
should i leave the "_" as part of [a-zA-Z0-9_]
If you remove the "_", then the test will fail if there is a "_" in the string tested. The only reason you see it so often is because it is a "word" character, for example, it is allowed in "word only" file names. In short, for your "name" test, you should remove the "_".

Quote:
5. using stripslashes() function
due to the above validation there is no way a user can enter special characters which could lead to sql injection. inspite of
this should i still use stripslashes to be on the safe side.
No, afaik good regex supersedes stripslashes. There may be a concern, however, if you are uploading to a db, that quotation marks are handled correctly.

This is my best effort but again, I'm no expert.

I would advise you to learn a bit more regex before you try to use it. (Of course, someone could fairly say that I should learn a bit more regex before I try to give advice about it.)
masonbarge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


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 On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How important are backlinks? mybmodel Search Engine Optimization (SEO) 21 February 18th, 2009 04:43 PM
question about validation and sql injection sudhakararaog PHP 5 May 21st, 2008 10:22 AM
Why Accessibility is Important for SEO Webnauts HTML, XHTML and CSS 0 November 13th, 2005 03:58 AM


Search Engine Optimization by vBSEO 3.2.0 RC8