Problem with white space!

Reply

Join Date: Sep 2009
Posts: 6
Reputation: Jeyush is an unknown quantity at this point 
Solved Threads: 0
Jeyush Jeyush is offline Offline
Newbie Poster

Problem with white space!

 
0
  #1
Sep 7th, 2009
Hi mate,

I use regex for my validation but @ this time I get confuse, how to use white space in it.

I want user to enter a city name, some city name contains white space like Los Angeles, New York, I have regex which is not allowing user to enter digits with city name.

like,
  1.  
  2. if(ereg('[^A-Za-z]', $city)) {
  3. echo "Only Characters Allowed";
  4. }
  5. else {
  6. echo "Thank You";
  7. }

This code does not allow user to enter digits in between city name, but this code does not allow me to enter space in between. If you have any suggestion for me then please draw my attention towards that.

Cheers!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 53
Reputation: SimonMayer is an unknown quantity at this point 
Solved Threads: 10
SimonMayer SimonMayer is offline Offline
Junior Poster in Training

Re: Problem with white space!

 
0
  #2
Sep 7th, 2009
I think you just need to add the space within the square brackets, like so:
  1.  
  2. if(ereg('[^A-Za-z ]', $city)) {
  3. echo "Only Characters Allowed";
  4. }
  5. else {
  6. echo "Thank You";
  7. }
Regards,

Simon Mayer
Website design by Ribbontree
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 178
Reputation: codejoust is an unknown quantity at this point 
Solved Threads: 18
codejoust's Avatar
codejoust codejoust is offline Offline
Junior Poster

Re: Problem with white space!

 
0
  #3
Sep 7th, 2009
  1. if(ereg('[^A-Za-z1-9 ]', $city)) {
  2. echo "Only Characters Allowed";
  3. }
  4. else {
  5. echo "Thank You";
  6. }
The REGEX engine allows a range of numbers, just like letters, in a white-list include, along with whitespace as you would just type it.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 6
Reputation: Jeyush is an unknown quantity at this point 
Solved Threads: 0
Jeyush Jeyush is offline Offline
Newbie Poster

Re: Problem with white space!

 
0
  #4
Sep 7th, 2009
Thanks buddy, it's worked, thanks for your time!!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 178
Reputation: codejoust is an unknown quantity at this point 
Solved Threads: 18
codejoust's Avatar
codejoust codejoust is offline Offline
Junior Poster

Re: Problem with white space!

 
0
  #5
Sep 7th, 2009
If you could mark the thread as solved, that would be great.
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,081
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Problem with white space!

 
0
  #6
Sep 8th, 2009
Just a note, you should avoid using ereg() as it is deprecated.

It is sad that it is, but it is. The PHP dev decided on using PECRE instead of POSIX Extended, those starting with "e". use the preg_ functions instead. ie: preg_match()
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

Tags
regex, space, white

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC