简体   繁体   English

使用带有posix语法的正则表达式来验证电子邮件地址

[英]Using a regular expression with posix syntax to validate an email address

Here is the validation that we have to use for email validation. 这是我们必须用于电子邮件验证的验证。

Using posix syntax: 使用posix语法:

^[[:graph:]]\\+@[[:graph:]]\\+\\.[[:graph:]]\\+$

I have written sample program to validate, but i have failed to give right Email address to fulfill posix syntax regular expression. 我已经编写了示例程序进行验证,但是我没有提供正确的电子邮件地址来满足posix语法正则表达式。 Could you please any one help me out to correct my below Java example. 您能否请任何人帮我纠正下面的Java示例。

Java Example: Java示例:

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class RegexMatches {

    public static void main(String args[]) {

      String email = "sudheer@gmail.com";
      String pattern ="^[[:graph:]]\\+@[[:graph:]]\\+\\.[[:graph:]]\\+$";
      //String pattern = ".+@.+\\.[a-z]+";// This is Working fine.

      if (!testRegex(email, pattern))
        System.out.println("Validator Exception");
      else
        System.out.println("Success");
    }

     public static boolean testRegex(String value, String regex) {
       Pattern pattern = Pattern.compile(regex);
       Matcher matcher = pattern.matcher(value);
       return matcher.matches();
    }
}

In java you can use: 在Java中,您可以使用:

String pattern ="^\\p{Graph}+@\\p{Graph}+\\.\\p{Graph}+$";

Reference 参考

  • Use \\\\p{Graph} in Java for [[:graph:]] in POSIX 在Java中将\\\\p{Graph}用于POSIX中的[[:graph:]]
  • No need to use double escape quantifier + 无需使用双逃逸量词+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 验证以 .services 结尾的电子邮件地址的 Java 正则表达式 - Java regular expression to validate email address that end with .services Java email 使用正则表达式验证地址 - Java email address validation using regular expression 如何使用正则表达式删除电子邮件地址中的点(。)字符 - How to remove dot (.) character in email address using regular Expression 使用正则表达式验证语句 - validate statement using regular expression 使用Java验证正则表达式 - validate Regular Expression using Java 正则表达式:电子邮件地址中的多个子域 - Regular expression: multiple subdomain in email address 使用特殊的电子邮件正则表达式 - Using a special email regular expression 如何通过电子邮件发送带有撇号的验证并使用正则表达式限制@符号后的点数。 (JAVA) - How to email validate with apostrophe and limit the number of dots after the @ symbol using Regular expression. (JAVA) 如何使用selenium web驱动程序从跨区文本中提取不是正则表达式格式的电子邮件地址? - How to extract an email address which is not in a regular expression format from a span text using selenium web driver? 在正则表达式中使用\\ P {M}时,避免在电子邮件地址中使用2个“ @”符号 - Avoiding 2 '@' signs in email address when using \P{M} within regular expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM