Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Wed Nov 24, 2010 8:23 am Reply with quote

trying to use preg_match to validate input from a text field, just curious if there is an easier way to do what I was trying to accomplish. The field should contain no spaces; only letters, numbers, and hyphens.

this seems to work...

Code:
if(!preg_match('/[^0-9A-Za-z-]/',$test_string)) {

echo $test_string.' OK <br />';
}else{
echo 'error '.$test_string.'  <br />';}


output
Code:
username OK

error user_name
error user name
error $username
error username!
error username?
user-name OK
 
View user's profile Send private message Visit poster's website
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Nov 24, 2010 10:00 am Reply with quote

I am not expert in regex, but that is basically what you want to do. I am not sure if you can tweak that or not.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Nov 26, 2010 11:05 am Reply with quote

That is about as simple as one can get. Looks good.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©