Jump to content

Simple regex help?


extrovertive

Recommended Posts

I thing he also wants to allow numbers and underscores:

 

/^(_|[a-zA-Z0-9])\w*$/

 

There is no need for alternations in this case.. you can simply use \w throughout (assuming it can start with an underscore or any number or letter:

 

#^\w+$#

 

Granted, depending on the locale, \w actually can match more than simply a-zA-Z0-9_.. it can also potentially match characters like à ò ì ù è by example (there are even more). So if it can start with an underscore, letter or number and must be any and only any of those throughout the string, then a simple character class with those would suffice:

 

#^[a-z0-9_]+$#i

Link to comment
https://forums.phpfreaks.com/topic/129453-simple-regex-help/#findComment-674037
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.