0

My input field allows only characters, no digits. I want when I type that the first character is in caps and small follows and anywhere is space do same, caps and small follows, and only one space should be allowed in the input field.

$(function() {
  $('#txttName').keydown(function(e) {
    if (e.shiftKey || e.ctrlKey || e.altKey) {
      e.preventDefault();
    } else {
      var key = e.keyCode;
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        e.preventDefault();
      }
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<p>Name</p>
<input id="txttName" value="">
j08691
  • 204,283
  • 31
  • 260
  • 272
Jeff Docm
  • 15
  • 2
  • 4
  • 5
    Note that many people's names do not follow this pattern. Read [Falsehoods Programmers Believe About Names](https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/) – Heretic Monkey Apr 21 '21 at 16:42
  • 2
    [You are imposing unreasonable restrictions on people's names](https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/). Mary Jane McDonald-Smyth wouldn't be able to enter her name with your restrictions. – Quentin Apr 21 '21 at 16:43

0 Answers0