ataria Posted November 24, 2006 Share Posted November 24, 2006 Hopefully I got the title right..alright, what I am looking to do..is to have the username be a-z, A-Z, 0-9 ONLY.In an if statement please. (if possible).thanks in advance! Quote Link to comment Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 [code]if (!ereg("~!@#$%^&*()_+=-,./<>?;':"[]\{}|",$username)) { echo "$username is not a valid username"; }[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2006 Share Posted November 24, 2006 I swear this question was asked half hour ago.[code=php:0]if ( preg_match('/^[a-zA-Z0-9_]+$/', $user) ) { // valid}[/code] Quote Link to comment Share on other sites More sharing options...
brendandonhue Posted November 24, 2006 Share Posted November 24, 2006 [code=php:0]if(ctype_alnum($username)){ //valid}[/code] Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Author Share Posted November 24, 2006 Awesome.Thanks guys! Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Author Share Posted November 24, 2006 Would it matter if I used all 3?such as, if (!ereg("~!@#$%^&*()_+=-,./<>?;':"[]\{}|",$username)) { echo "$username is not a valid username"; }elseif ( preg_match('/^[a-zA-Z0-9_]+$/', $user) ) { // valid}elseif(ctype_alnum($username)){ //valid}? Quote Link to comment Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 I would stick with one of them. Use thorpes. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Author Share Posted November 24, 2006 Alright.Thanks! Quote Link to comment Share on other sites More sharing options...
brendandonhue Posted November 24, 2006 Share Posted November 24, 2006 [quote author=mgallforever link=topic=116102.msg472869#msg472869 date=1164331334]Use thorpes.[/quote]Out of curiosity, why that one? Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Author Share Posted November 24, 2006 Hey.Would that make spaces not allowed? Quote Link to comment Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 It would make it so only a-z, A-Z and 0-9 are allowed. Quote Link to comment Share on other sites More sharing options...
ataria Posted November 24, 2006 Author Share Posted November 24, 2006 I take that as a yes. XD Quote Link to comment Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 And brendan, I chose his because I wasn't sure on ataria's PHP Experience level and to show that it would only include those. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.