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 Quote 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 Quote 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? Quote 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 Quote 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 Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/137886-regular-expressions/#findComment-720687 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.