0

I have this code which converts some text to lower case but is it possible to convert to 1st character to a capital letter followed by the remaining characters being lower case?

NWF$(document).ready(function() {
  NWF$('#' + varTitle).change(function() {
    this.value = this.value.toLowerCase();
  });
});


Thanks to Ulysse BN , I got the hint to use the following

this.value = this.value[0].toUpperCase() + this.value.slice(1).toLowerCase()

which works excellent but if you wanted to use VGA as capital then this would not be possible, it is a catch 22 situation. Just wanted to avoid users from typing everything in capital (I hate it).

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
Bucki
  • 33
  • 1
  • 1
  • 7
  • sentence case.. – epascarello Feb 04 '19 at 13:26
  • What are the requirements, does the text have to *be* transformed (so JavaScript) or merely *look* transformed (so CSS might be a possibility)? Should the first letter *always* appear/be uppercase, for example: `’pH: a discussion’` should become what, after processing? Yep, it’s an edge case, plan for those in advance. – David Thomas Feb 04 '19 at 13:29
  • @DavidThomas example: HELLO MY NAME IS should be rewritten into "Hello my name is" because if you do every word with capital first letter, it would make it look silly ... not sure if this is even possible. I am using the above code in sharepoint Nintex. – Bucki Feb 04 '19 at 13:48

1 Answers1

1

You could lowercase the whole string except the first letter:

let value = 'HEYhoHAHA'
value = value[0].toUpperCase() + value.slice(1).toLowerCase()

document.write(value)
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82