Need help to get correct regex format for usernames

I need help getting the regex format of my usernames correct. It suppose to require 3 letters in it and allow no spaces or _. I think I'm on the right track so far with this:

validates_format_of :username, :with => /([^a-zA-Z]*([a-zA-Z]+)[^a-zA-Z]*){3,}/ 

This allows spaces though and I'm not sure if this is correct in general. What corrections do I need for this regex to get rid of the ability to use spaces or _?

Answers


If you mean it has to be all letters, it's just:

/^[a-zA-Z]{3,}$/

Otherwise, use a lookahead:

/^(?=(.*[a-zA-Z]){3})[allowed characters here]+$/

Need Your Help

Create PDFs from multipage forms in WebObjects

java pdf webobjects

I would like to automatically generate PDF documents from WebObjects based on mulitpage forms. Assuming I have a class which can assemble the related forms (java/wod files) is there a good way to t...

Change Output Redirection of Running Process

python subprocess io-redirection

I have a parent Python script that launches a child (which launches grandchildren), and after some time, I terminate the child, but the grandchildren continue to pump to stdout. After I kill the ch...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.