Nhoj Posted September 6, 2006 Share Posted September 6, 2006 I just recently developed a user registration system, not a hard thing at all to make, and i use the code:[code]preg_match_all('/(?:([a-z]+)|.)/i', $_POST['username'], $matches);$_POST['username'] = implode('', $matches[1]);[/code]To strip EVERYTHING that is not alpha numeric from all of the registration inputs and it works exactly how I want it to, however, this also strips the @ sign and periods, which is bad for e-mails.Is there any way to have it do what it does now except add '@' and '.' to the safe list? This way only alphanumeric characters and those two symbols will remain.Thanks,John Link to comment https://forums.phpfreaks.com/topic/19944-preg_match-alphanumeric-check-with-two-exceptions/ Share on other sites More sharing options...
obsidian Posted September 6, 2006 Share Posted September 6, 2006 i would just use preg_replace() instead like this:[code]<?php$String = preg_replace('|[^a-z0-9.@]|', '', $String);?>[/code]make sense? Link to comment https://forums.phpfreaks.com/topic/19944-preg_match-alphanumeric-check-with-two-exceptions/#findComment-87368 Share on other sites More sharing options...
Nhoj Posted September 6, 2006 Author Share Posted September 6, 2006 Not sure why I didn't even consider preg_replace, anyway, thanks. I'm using what you suggested with the exception that I added an extra A-Z to allow capital letters. Link to comment https://forums.phpfreaks.com/topic/19944-preg_match-alphanumeric-check-with-two-exceptions/#findComment-87382 Share on other sites More sharing options...
obsidian Posted September 6, 2006 Share Posted September 6, 2006 [quote author=Nhoj link=topic=107154.msg429503#msg429503 date=1157574158]Not sure why I didn't even consider preg_replace, anyway, thanks. I'm using what you suggested with the exception that I added an extra A-Z to allow capital letters.[/quote]you could just add the "i" for case insensitivity:[code]<?php$String = preg_replace('|[^a-z0-9.@]|i', '', $String);?>[/code] Link to comment https://forums.phpfreaks.com/topic/19944-preg_match-alphanumeric-check-with-two-exceptions/#findComment-87386 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.