aeroswat Posted January 11, 2010 Share Posted January 11, 2010 I need to only allow my string to have a combination of the following 0-9 and A-Z. So far I have this which gives me only 0-9 preg_replace("/[^0-9]/", "", $bookISBN) Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/ Share on other sites More sharing options...
JonnoTheDev Posted January 11, 2010 Share Posted January 11, 2010 [A-Z0-9]+ Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992850 Share on other sites More sharing options...
JAY6390 Posted January 11, 2010 Share Posted January 11, 2010 /[^0-9a-z]/i @neil - your A-z will allow all characters between Z and a in the ASCII table too Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992851 Share on other sites More sharing options...
aeroswat Posted January 11, 2010 Author Share Posted January 11, 2010 /[^0-9a-z]/i @neil - your A-z will allow all characters between Z and a in the ASCII table too I think there are no characters between cap A and cap Z on the ASCII table? And I need it to be able to recognize both lowercase and uppercase if that makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992853 Share on other sites More sharing options...
JAY6390 Posted January 11, 2010 Share Posted January 11, 2010 My regex does...and yes there are (between capital A and lowercase z which is what his expression is) http://www.asciitable.com/ Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992857 Share on other sites More sharing options...
aeroswat Posted January 11, 2010 Author Share Posted January 11, 2010 My regex does...and yes there are http://www.asciitable.com/ There are between cap Z and low a but not between cap A and cap Z. So I'm seeing this on some sites... would this do what I want it to? /[^0-9A-Za-z]/ I want to use ur example Jay but I would think that it is case sensitive and being a ISBN there will mostly be capitals unless the person is too lazy to put caps Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992859 Share on other sites More sharing options...
JAY6390 Posted January 11, 2010 Share Posted January 11, 2010 oops. Thats what I meant. Yes it will although I don't see what was wrong with my regex? it was case insensitive (hence the i after the /) so it does the same thing Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992861 Share on other sites More sharing options...
aeroswat Posted January 11, 2010 Author Share Posted January 11, 2010 oops. Thats what I meant. Yes it will although I don't see what was wrong with my regex? it was case insensitive (hence the i after the /) so it does the same thing Sorry I didn't know what the /i meant. I don't know much about reg expressions at all. So would this be what i would do to remove all of the non a-z's and 0-9's preg_replace("/[^0-9a-z]/i", "", $bookISBN) Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992864 Share on other sites More sharing options...
JonnoTheDev Posted January 11, 2010 Share Posted January 11, 2010 Use ereg as opposed to preg. eregi is case sensitive. preg is obsolete or will be soon $result = eregi_replace('[^0-9a-z]', '', $bookISBN); Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992867 Share on other sites More sharing options...
JAY6390 Posted January 11, 2010 Share Posted January 11, 2010 Yeah that will work fine. preg is OBSOLETE??? That is nonsense. It's recommended to use preg over eregi all the time. Where on earth did you get that idea from? Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992868 Share on other sites More sharing options...
aeroswat Posted January 11, 2010 Author Share Posted January 11, 2010 Use ereg as opposed to preg. eregi is case sensitive. preg is obsolete or will be soon $result = eregi_replace('[^0-9a-z]', '', $bookISBN); I'm seeing that the ereg functions were deprecated in 5.3 anyways thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992870 Share on other sites More sharing options...
JAY6390 Posted January 11, 2010 Share Posted January 11, 2010 Yes and removed in PHP6 http://www.php.net/eregi Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992872 Share on other sites More sharing options...
JonnoTheDev Posted January 11, 2010 Share Posted January 11, 2010 Yes and removed in PHP6 http://www.php.net/eregi Sorry wrong way round. ereg is obsolete not preg, my bad I knew it was one of them. $result = preg_replace('/[0-9a-z]/i', '', $subject); Quote Link to comment https://forums.phpfreaks.com/topic/188068-whats-the-expression-for-alpha-numeric/#findComment-992886 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.