codrgii Posted August 31, 2009 Share Posted August 31, 2009 using preg replace, how do i make it accept only smallcase a-z, capitals A-Z, numbers 0-9 and the characters : and _ and replace any other characters not in this list to ''? i got the numbers and letters working but not the character : and _, does anyone know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/172561-php-question/ Share on other sites More sharing options...
emehrkay Posted August 31, 2009 Share Posted August 31, 2009 I'm pretty sure it is [a-zA-Z0-9:_] Or even \w:_ Quote Link to comment https://forums.phpfreaks.com/topic/172561-php-question/#findComment-909667 Share on other sites More sharing options...
codrgii Posted August 31, 2009 Author Share Posted August 31, 2009 and how would i use preg_replace for something like emails, where it only accepts @, . and numbers and letters (smallcase / uppercase)? Quote Link to comment https://forums.phpfreaks.com/topic/172561-php-question/#findComment-909701 Share on other sites More sharing options...
Garethp Posted August 31, 2009 Share Posted August 31, 2009 preg_match('~[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+~', $input); Quote Link to comment https://forums.phpfreaks.com/topic/172561-php-question/#findComment-909705 Share on other sites More sharing options...
wildteen88 Posted August 31, 2009 Share Posted August 31, 2009 I would recommend you to take a look at regular-expressions.info for common regex patterns. It helped me understand regex when I was learning. Quote Link to comment https://forums.phpfreaks.com/topic/172561-php-question/#findComment-909706 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.