Simplifying Organization Name Regex

This topic is about simplifying a regex.

I have been "Client Side" validating a form I created using Javascript. This form requires a business to signup using it's company name. I have created a regex that seems to work well, but it does have a couple issues. First issue is that the regex only allows companies, who's names are 5 words or less, to be considered valid. I know how I can make it allow more words but that would require more code, which could be considered sloppy work. Is there a way that I can correct the following regex to allow companies to sign up, and not worry about how many words they have in their name? Would XSS be an issue with the way I currently have my regex? Thanks for all and any help.

}
if(!Bname.match(/^[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*$|^[0-9A-Za-z'-]*$|^[0-9A-Za-z'-]*
\s{1}[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*$|^[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*\s{1}[0-9A-
Za-z'-]*\s{1}[0-9A-Za-z'-]*$|^[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*
\s{1}[0-9A-Za-z'-]*\s{1}[0-9A-Za-z'-]*$/))
{

Answers


You can extend your regex like this:

Bname.match(/^[0-9A-Za-z'-]+(?:\s[0-9A-Za-z'-]+)*$/)

However, it will not match names with accented characters and other symbols that may exist in a company name (like Yahoo!)


Need Your Help

Handling scrolling nested UIScrollViews scrolling in the same direction

ios objective-c iphone uitableview uiscrollview

I am trying to implement something similar to Twitter iOS App (profile page)

FluentNHibernate mapping of composite foreign keys

c# nhibernate fluent-nhibernate nhibernate-mapping

I have an existing database schema and wish to replace the custom data access code with Fluent.NHibernate. The database schema cannot be changed since it already exists in a shipping product. And i...