This is a discussion on "VERY IMPORTANT question about validation using php" within the PHP Forum section. This forum, and the thread "VERY IMPORTANT question about validation using php are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
VERY IMPORTANT question about validation using php
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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. |
|
|
|
#2
|
|||
|
|||
|
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 Blog Entry: Cross browser nuisance (Feb 11th, 2008)
Last edited by RohanShenoy; Mar 9th, 2008 at 14:47. |
|
#3
|
|||||
|
|||||
|
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:
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:
Quote:
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:
Quote:
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.) |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How important are backlinks? | mybmodel | Search Engine Optimization (SEO) | 19 | Oct 5th, 2008 17:38 |
| question about validation and sql injection | sudhakararaog | PHP Forum | 5 | May 21st, 2008 14:22 |
| Why Accessibility is Important for SEO | Webnauts | Web Page Design | 0 | Nov 13th, 2005 07:58 |