title: How to use .setError
body: <p>I use .setError function. But it checks the text field only when the save button is clicked, go to SecondActivity and press Back button on device to see it can't be left empty!</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_new_card);
  
  save=(Button)findViewById(R.id.save);
  save.setOnClickListener(new View.OnClickListener() {
  
  @Override   
  public void onClick(View v) {
  
  EditText Name2 = (EditText)findViewById(R.id.txtName);
  if( Name2.getText().toString().length() == 0 )
  Name2.setError( "First name is required!" );
  
  Intent intent = new Intent(NewCard.this, Template.class);
  startActivity(intent);
  
  }
  });
  </code></pre>
  
  <p>Any idea on how i can check when button is clicked but not proceeding to SecondActivity if Name2 is blank? And beside length(), i also want to check for numbers, undesired characters etc. if possible. Thanks for assistance.</p>