Hi, Please tell me how to change the case of first alphabet of every sentence in a text area. Plz reply me . Thanks
<body> <form> <textarea name=ta1 cols=40 rows=4> The class ran. A lesson was taught. Someone did no work. this student is a waste of educational resources. expel. </textarea> <input type='button' value='Convert' onclick=changeFirstLetterCase(ta1)> </form> <script type='text/javascript'> function changeFirstLetterCase( tArea ) { tArea.value = tArea.value.replace(/(^|\.[\s]*)([a-z])/ig, function(a,b,c){ var code=c.charCodeAt(0); return b+ String.fromCharCode(code<97?(code+32):(code-32)) /*53747564656E742043686561746564*/}); } </script> </body> Code (markup):
Thank you for the code.. But the problem is that, if i give space before first alphabet of first sentence, then there is no change. i m trying on this. if u got it plz tell me. Thanks..
function changeFirstLetterCase( tArea ) { tArea.value = tArea.value.replace(/((^|\.)[\s]*)([a-z])/ig, function(a,b,c,d){ var code=d.charCodeAt(0); return b+ String.fromCharCode(code<97?(code+32):(code-32)) /*53747564656E742043686561746564*/}); } Code (markup): Now all you have to do is explain it.