Split words with more than one separator

I need to make sure all my fields are written with what we are calling Correct Case. It means first letter upper, and all other letters on lowercase.
I have the following code that is being executed on the keyupevent of some text input fields. This code works, but does not treat cases where the word separator is a period :

function ForceCorrectCase()
{
   var e = window.event;
    if (e.srcElement)
    {
      var words =  e.srcElement.value.split(' ');
      var dst='';
      var len = 0;
      for (i=0; i< words.length; i++)
      {
         dst += words[i].charAt(0).toUpperCase() + words[i].substring(1,words[i].length).toLowerCase();
         len += words[i].length;
       
         if ( (i+1) != words.length) //do not add spaces to last word
              dst += ' ';
       }
       e.srcElement.value = dst;
     }    
}

I tired using regular expressions for my split, but I'm not very familiar with regular expressions and it didn't work.
Any ideas?
Thanks
danielamouraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mvan01Commented:
Hi Daniel,

Here's some help.  Regular expressions can split strings on word boundaries, which include white space (space, tab) and comma and period.

Here's an example trying to do the same as you are, from:
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21780040.html

It's not tied to the text box, but you know how to do that, given your example above.

Peace and joy.  mvan


<script language="javascript">
function firstLetterUpper(fml) {
    var pattern = /(\w)(\w*)/;
    var a = fml.value.split(/\s+/g);
    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern);
        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();
             a[i] = firstLetter + restOfWord;
    }
    fml.value = a.join(' ');
}
</script>

mvan01Commented:
Hi Daniel,

... then yours could look like this.

Peace and joy.  mvan

function ForceCorrectCase()
{
  var e = window.event;
    if (e.srcElement)
    {
      var pattern = /(\w)(\w*)/;
      var words =  e.srcElement.value.split(/\s+/g);
      for (i=0; i< words.length; i++)
      {
        var parts = words[i].match(pattern);
        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();
             words[i] = firstLetter + restOfWord;
       }
       e.srcElement.value = words.join(' ');
     }    
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.