Need Sentence Case not ProperCase - Please

I need a javascript that does Sentence Case as in MS Word.  Title or ProperCase caps the first letter of every word.  exp.. "This Is The Day.." - Sentence Case is "This is the day."

I have search in many forum and can not find wihat I am looking for.  I have found some samples you can put in Access of the after update, and by putting  a public function in a module. ProperCase Not Sentence Case.

I have found some examples as the one below to use in javascript.  This is the one I pefer.

<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>

I just need it to just cap the first letter in the sentence and then after the peroid or question mark cap the first letter of the next sentence.

I am sure this can be done, but I can't seem to fiqure it out.

Thank you in advance.
bburdenAsked:
Who is Participating?
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.

StormyWatersCommented:
function capitalize(str) {
  var re = /([?\.\!])( *)(\w)/g;
      str = str.replace(re, function(x){return RegExp.$1 + RegExp.$2 + RegExp.$3.toUpperCase()});
      return str.replace(/^./,function(x){return x.toUpperCase()}); //Capitalize first char, inelegantly.
      
}

Capitalizes any alphanumeric after ? or . or ! followed by any amount of spaces.

Very similar (in fact, a modified function) to http:Q_21779941.html
0
ZvonkoSystems architectCommented:
Simmelar, but still different:

<script>

var theText = "This Is The first Day. This Is The second Day. This Is The third Day.";

theText = theText.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});

document.write(theText);
</script>

0
bburdenAuthor Commented:
Hello all and thanks.  I guess I did not explain myself clearly, I am bad about that.  I need to associate the above javascript with a text box or text area.  If the text area is filled in incorrectly by the user, for example they type in all CAPS  I want it to convert to Sentence Case as the example I have listed.  I do not want every letter to be cap of each word.

Maybe I am just not getting what you guys are saying please forgive my ingorance.

<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>

</head>

<body>
<form>
<b>
<p><input type="text" name="fml" size="30" onChange="return firstLetterUpper(this);"></p>
</b>
  <textarea name="textfield" cols="50" rows="4" onChange="return firstLetterUpper(this);"></textarea>

<b>
<p><input type="submit" value="Submit" name="B1" ID="Submit1">
</b>

Thanks again for all your help.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ZvonkoSystems architectCommented:
And I guess you did not test my version:

function firstLetterUpper(fml) {
  fml.value = fml.value.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});
}

0

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
mvan01Commented:
Hi bburden,

Zvonko provided a top notch solution once again.  He provides a snippet to show how and/or that it works, then he's on to help 100s of other people.  You have working code in your example, and so you just need to use his solution in the same manner...

function sentenceCase(aForm) {
    var theText = aForm.value;
    theText = theText.toLowerCase().replace(/(^\s*\w|[\.\!\?]\s*\w)/g,function(c){return c.toUpperCase()});
    aForm.value = theText;
}

You can call that function the same as you called your proper case function.  Sweet.  I'd give him an A!

mvan
0
mvan01Commented:
Look at that, he was back to show how it fit into your program ... quicker than I could type my message!

Thanks for sharing your wisdom, Zvonko.

mvan
0
bburdenAuthor Commented:
I was never doubting Zvonko , I said it was just me not getting it.  That why I said in advance forgive for my ingornace.  I have given him a A grade and accepted his answer.  

I am not astute as most in here, but I do know how to appreciate help that is given.

Thanks again Zvonko
0
mvan01Commented:
Sorry, I didn't mean to call your gratitude or appreciation into question.  I just meant that my putting it into a function wouldn't merit any me any credit - he did the real work ... and while I was typing my message, he went ahead and put it into a function too (I didn't see that before I hit the submit on mine).

mvan
0
bburdenAuthor Commented:
All is well, Mvan, Everthing is Everthing. I do appreciate all you guys in here.  To everyone have a great week.

Later until the next time.
0
ZvonkoSystems architectCommented:
You are welcome.
And please consider splitting points to all experts who invested time and efforts to code the solution AND to explain the solution in plain English words to help you understand.

Thanks mvan.

0
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.