Java Regular Expression match email

Description

Java Regular Expression match email


//package com.demo2s;

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "web@example.com";
        System.out.println(isEmail(str));
    }//  w w w  . j av  a2  s .  co m

    private static final Pattern emailPattern = Pattern
            .compile("^[\\w]+[\\w\\.\\-\\+\\_]+@[\\w\\.\\-\\_]+\\.[\\w]+$");

    public static boolean isEmail(String str) {
        return emailPattern.matcher(str).matches();
    }
}



PreviousNext

Related