brem13 Posted August 18, 2010 Share Posted August 18, 2010 hey, i was wondering how i would make a preg match check for special characters, i would only like to allow an underscore _ and a dash - i'm currently using preg_match("/[^0-9]+$/",$getUser) but thats not working right Link to comment https://forums.phpfreaks.com/topic/211113-preg-match-for-special-chars/ Share on other sites More sharing options...
btherl Posted August 18, 2010 Share Posted August 18, 2010 If you have a list of characters to allow, just list those characters, eg preg_match("/^[0-9a-zA-Z_-]+$/", $getUser); That allows 0-9, a-z, A-Z, underscore and dash only. Make sure the dash appears last or first, so it doesn't get mistaken for a range of characters. Link to comment https://forums.phpfreaks.com/topic/211113-preg-match-for-special-chars/#findComment-1100976 Share on other sites More sharing options...
brem13 Posted August 18, 2010 Author Share Posted August 18, 2010 thank you! Link to comment https://forums.phpfreaks.com/topic/211113-preg-match-for-special-chars/#findComment-1100978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.