title: Mobile application phone, email edit text validation using expressions
body: <p>I need to validate phone and email Edit texts in android application.</p>
  
  <p>Email text I want it to match the familiar email syntax "example@gmail.com"</p>
  
  <p>Phone text I want it to be like this "xxx-xxx-xxxx" where x is numbers only</p>
  
  <p>I want the validation to happen OnFocusChangeListener</p>
  
  <pre><code>phoneNum.setOnFocusChangeListener(new View.OnFocusChangeListener() {
      @Override
      public void onFocusChange(View view, boolean hasFoucs) {
          if(!hasFoucs){
              Phone = phoneNum.getText().toString();
              if (!Phone.matches("^\\d{3}-\\d{3}-\\d{4}$/")){
                  phoneNum.setBackgroundColor(Color.parseColor("#FFBABA"));
                  Toast.makeText(ctx,"Phone Syntax incorrect",Toast.LENGTH_LONG).show();
                  flag_phone = 0;
              }
              else {
                  phoneNum.setBackgroundColor(Color.WHITE);
                  flag_phone =1;
              }
          } else {
              phoneNum.setBackgroundColor(Color.WHITE);
          }
      }
  });
  </code></pre>
  
  <p>and for email, I tried this</p>
  
  <pre><code>    EmailTxt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View view, boolean hasFoucs) {
              if(!hasFoucs){
                  Email = EmailTxt.getText().toString();
                  if (!Email.matches("^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$")){
                      EmailTxt.setBackgroundColor(Color.parseColor("#FFBABA"));
                      Toast.makeText(ctx,"Email should be 10 numbers",Toast.LENGTH_LONG).show();
                      flag_email = 0;
                  }
                  else {
                      EmailTxt.setBackgroundColor(Color.WHITE);
                      flag_email =1;
                  }
              } else {
                  EmailTxt.setBackgroundColor(Color.WHITE);
              }
  
          }
      });
  </code></pre>
  
  <p>if its possible to put the expression in the matches() instead of using other approaches it will be more suitable for me, please.</p>