943,925 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1802
  • PHP RSS
Sep 7th, 2009
0

Problem with white space!

Expand Post »
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,
text Syntax (Toggle Plain Text)
  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!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jeyush is offline Offline
10 posts
since Sep 2009
Sep 7th, 2009
0

Re: Problem with white space!

I think you just need to add the space within the square brackets, like so:
PHP Syntax (Toggle Plain Text)
  1.  
  2. if(ereg('[^A-Za-z ]', $city)) {
  3. echo "Only Characters Allowed";
  4. }
  5. else {
  6. echo "Thank You";
  7. }
Reputation Points: 14
Solved Threads: 10
Junior Poster in Training
SimonMayer is offline Offline
53 posts
since Apr 2008
Sep 7th, 2009
0

Re: Problem with white space!

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 18
Solved Threads: 21
Junior Poster
codejoust is offline Offline
180 posts
since Jul 2009
Sep 7th, 2009
0

Re: Problem with white space!

Thanks buddy, it's worked, thanks for your time!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Jeyush is offline Offline
10 posts
since Sep 2009
Sep 7th, 2009
0

Re: Problem with white space!

If you could mark the thread as solved, that would be great.
Thanks!
Reputation Points: 18
Solved Threads: 21
Junior Poster
codejoust is offline Offline
180 posts
since Jul 2009
Sep 8th, 2009
0

Re: Problem with white space!

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()
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Insert PHP block in database using PHP
Next Thread in PHP Forum Timeline: Classes & Method help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC