title: Auto remove leading space of any text of EditText?
body: <p><strong>Description</strong></p>
  
  <p>I am developing one app in which I have registration page.
  Inside registration page, I am doing registration by getting user's full name and mobile number.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>While getting user's full name in edit text sometimes the user is pressing space bar before type his/her name.</p>
  
  <p>I need you disable space-bar key before typing any text white user start typing his name I want to enable space-bar key. So that user can enter space between his/her Middle name and Last name.</p>
  
  <p><strong>What I have tried?</strong></p>
  
  <p><strong>Answer</strong> </p>
  
  <p>I am using text watcher in edit text. </p>
  
  <pre class="lang-ava prettyprint-override"><code>user_name.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
                  inputLayoutname.setError(null);
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
  
                  System.out.println(TAG+" s :"+s+ " start :"+start+" Before : "+before+" Count: "+count);
                  String str = s.toString();
  
                  if(str.length() &gt; 0 &amp;&amp; str.contains(" "))
                  {
                      user_name.setError("Space is not allowed");
                      user_name.setText("");
                  }
              }
  
              @Override
              public void afterTextChanged(Editable s) {    
  
                  if (user_name.getText().length() &gt; 0)
                      inputLayoutname.setError(null);
              }
          });
  </code></pre>
  
  <p><strong>What problem coming when I am implementing this code?</strong></p>
  
  <p>While user pressing firstly it automatically removing space suddenly. 
  But when user trying to enter space between full name, it's again removing all text and showing empty edit text. </p>
  
  <p><a href="https://i.stack.imgur.com/I9fMM.png" rel="nofollow noreferrer">screen 1 while entering only space</a>
  <a href="https://i.stack.imgur.com/I9fMM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I9fMM.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/lEQP5.png" rel="nofollow noreferrer">Here I am entering my Name  and want to enter last name or middle name of space </a>
  <a href="https://i.stack.imgur.com/lEQP5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lEQP5.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ZUFzx.png" rel="nofollow noreferrer">Here when I am entering space after my first name</a>
  <a href="https://i.stack.imgur.com/ZUFzx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZUFzx.png" alt="enter image description here"></a></p>