[英]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示例。
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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.