0

I want to check email by using regular expression.I checked ([-\w.]+@[-\w.]+.[_-\w.]) for email regular expression.But "character class may not be used inside character range" error occurs.How can I do that?

3 Answers3

0

try this

String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z._-a-zA-Z0-9]+";
Yaseen Ahmad
  • 1,807
  • 5
  • 25
  • 43
0

You need to check reqular expressions inside matches function like this

 if(editText.getText().toString().matches("^[a-zA-Z0-9._%+-]+[@]{1}[a-zA-Z0-9.-]+[.]{1}[a-zA-Z]{2,6}$")){
        //Valid email address
 }else{
        //Wrong email address
 }
Jinesh Francis
  • 3,377
  • 3
  • 22
  • 37
0
static String emailExpression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,20}$";
static Pattern emailPattern = Pattern.compile(emailExpression, Pattern.CASE_INSENSITIVE);

Validation

 if(emailValidation(editText.getText().toString()))
{
//Valid
}
else
{
// Invalid
}

function call validation

 public static boolean emailValidation(String s)
{
    if( s == null)
    {
        return false; 
    }
    else
    {
        m = emailPattern.matcher(s);
        return m.matches();
    }
}
Arjun saini
  • 4,223
  • 3
  • 23
  • 51