regular expression for email validation in Java

后端 未结 6 1137
渐次进展
渐次进展 2020-12-05 08:46

I am using the follwoing regular expression

(\".+@.+\\\\.[a-z]+\")

Bit it accepts #@#.com as a valid email. What\'s the pattern I should u

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 09:39

    import java.util.regex.*;
    
    class ValidateEmailPhone{
    
        public static void main(String args[]){
    
            //phone no validation starts with 9 and of 10 digit
            System.out.println(Pattern.matches("[9]{1}[0-9]{9}", "9999999999"));
    
            //email validation
            System.out.println(Pattern.matches("[a-zA-Z0-9]{1,}[@]{1}[a-z]{5,}[.]{1}+[a-z]{3}", "abcd@gmail.com"));
        }
    }
    

提交回复
热议问题