hassank1 Posted December 21, 2008 Share Posted December 21, 2008 I've found this regular expression that allows only alphanumeric characters : [^A-Za-z0-9] how can I modify it so it can also accept the minus "-" and the underscore "_" ?? thanks Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/ Share on other sites More sharing options...
Adam Posted December 21, 2008 Share Posted December 21, 2008 [^A-Za-z0-9\-_] A Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720665 Share on other sites More sharing options...
Adam Posted December 21, 2008 Share Posted December 21, 2008 A better way would be: [\w\-] By the way i don't think ^ should be in there? I'm no regular expressions expert, by far, but i believe that means NOT these characters. Anyone? Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720666 Share on other sites More sharing options...
hassank1 Posted December 21, 2008 Author Share Posted December 21, 2008 thanks.. however another thing I forgot to mention I don't want to allow underscore or minus at the 1st position : ex: _test or -test <-- wrong Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720667 Share on other sites More sharing options...
Adam Posted December 21, 2008 Share Posted December 21, 2008 [a-zA-Z0-9][\w\-] A Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720673 Share on other sites More sharing options...
Adam Posted December 21, 2008 Share Posted December 21, 2008 [a-zA-Z0-9][\w\-]+ That's perhaps more correct? As I said, regular expressions aren't my strongest point! Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720687 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.