0

As the title says, I need a solution for also working with umlauts like ö, Ö, ä, Ä, ü, Ü and ß. The following script capitalizes each first letter, but has problems with umlauts like the ones stated above. The output of the script is like the following:

  • Corey Jones
  • Corey.Jones
  • Corey-Jones
  • Corey,Jones
  • Corey/Jones
  • Corey-Jones

and so on. This is just fine! But when I want to use umlauts, the output is like:

  • CöRey JöNes
  • öKan üSal

Every umlaut gets to lowercase, even if it's the first letter. I just want them to fit in the same as the regular alphabet. My content type is set to utf-8 and the document saved in utf-8 w/o BOM. I already tried to add these umlauts to the regex pattern, but neither of them worked.

$(document).ready(function() {
 $('.check').change(function() {
  if ($('.check:checked').length) {
   $('#submit').removeAttr('disabled');
  } else {
   $('#submit').attr('disabled', 'disabled');
  }
 });
     
 $.fn.capitalize = function() {
  $.each(this, function() {
   this.value = this.value.replace(/\b[a-z]/gi, function($0) {
    return $0.toUpperCase();
   });
   this.value = this.value.replace(/@([a-z])([^.]*\.[a-z])/gi, function($0, $1) {
    console.info(arguments);
    return '@' + $0.toUpperCase() + $1.toLowerCase();
   });
  });
 }   

 $("#vname").keyup(function() {
  $(this).capitalize();
 }).capitalize();
  
 $("#nname").keyup(function() {
  $(this).capitalize();
 }).capitalize();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="vname" id="vname" placeholder="Vorname" required="required" class="visible" />&nbsp;
<input type="text" name="nname" id="nname" placeholder="Nachname" required="required" class="visible" />
montreal
  • 35
  • 7
  • 1
    This is not a jQuery issue as umlauts don't get captured by `[a-z]`, see [**http://stackoverflow.com/questions/22017723/regex-for-umlaut**](http://stackoverflow.com/questions/22017723/regex-for-umlaut) how to capture the `unicode codes` for the required letters. – Nope Mar 28 '17 at 08:57
  • Thanks! But I implemented "\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df" (even separated the capital ones from the lowercased) in every constellation and the result differs only in capital letter directly before a regular letter. When I want to start with an umlaut, it's still lowercase. – montreal Mar 28 '17 at 09:37
  • I helped myself. – montreal Apr 07 '17 at 13:03
  • Sweet, you can post the solution and accept your own answer by the way. SO even encourages that :) – Nope Apr 07 '17 at 13:09

0 Answers0