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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.