这个是它的源码。包含了org.apache.oro.text.perl.Perl5Util;这个你在找找看吧。 /** * <p>Checks if a field has a valid e-mail address.</p> * <p>Based on a script by Sandeep V. Tamhankar ([email protected]), * http://javascript.internet.com</p> * * @param value The value validation is being performed on. */ public static boolean isEmail(String value) { boolean bValid = true; try { String specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; String validChars = "[^\\s" + specialChars + "]"; String quotedUser = "(\"[^\"]*\")"; String atom = validChars + '+'; String word = "(" + atom + "|" + quotedUser + ")"; // Each pattern must be surrounded by / String legalAsciiPat = getDelimittedRegexp("^[\\000-\\177]+$"); String emailPat = getDelimittedRegexp("^(.+)@(.+)$"); String ipDomainPat = getDelimittedRegexp("^(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})$"); String userPat = getDelimittedRegexp("^" + word + "(\\." + word + ")*$"); String domainPat = getDelimittedRegexp("^" + atom + "(\\." + atom + ")*$"); String atomPat = getDelimittedRegexp("(" + atom + ")"); Perl5Util matchEmailPat = new Perl5Util(); Perl5Util matchUserPat = new Perl5Util(); Perl5Util matchIPPat = new Perl5Util(); Perl5Util matchDomainPat = new Perl5Util(); Perl5Util matchAtomPat = new Perl5Util(); Perl5Util matchAsciiPat = new Perl5Util(); boolean ipAddress = false; boolean symbolic = false; if (!matchAsciiPat.match(legalAsciiPat, value)) { return false; } // Check the whole email address structure bValid = matchEmailPat.match(emailPat, value); if (value.endsWith(".")) { bValid = false; } // Check the user component of the email address if (bValid) { String user = matchEmailPat.group(1); // See if "user" is valid bValid = matchUserPat.match(userPat, user); } // Check the domain component of the email address if (bValid) { String domain = matchEmailPat.group(2); // check if domain is IP address or symbolic ipAddress = matchIPPat.match(ipDomainPat, domain); if (ipAddress) { // this is an IP address so check components for (int i = 1; i <= 4; i++) { String ipSegment = matchIPPat.group(i); if (ipSegment != null && ipSegment.length() > 0) { int iIpSegment = 0; try { iIpSegment = Integer.parseInt(ipSegment); } catch (Exception e) { bValid = false; } if (iIpSegment > 255) { bValid = false; } } else { bValid = false; } } } else { // Domain is symbolic name symbolic = matchDomainPat.match(domainPat, domain); } if (symbolic) { // this is a symbolic domain so check components String[] domainSegment = new String[10]; boolean match = true; int i = 0; int l = 0; while (match) { match = matchAtomPat.match(atomPat, domain); if (match) { domainSegment[i] = matchAtomPat.group(1); l = domainSegment[i].length() + 1; domain = (l >= domain.length()) ? "" : domain.substring(l); i++; } } int len = i; if (domainSegment[len - 1].length() < 2 || domainSegment[len - 1].length() > 4) { bValid = false; } // Make sure there's a host name preceding the domain. if (len < 2) { bValid = false; } } else { bValid = false; } } } catch (Exception e) { bValid = false; } return bValid; }
才接触java和jsp不久,望请各位老大说明白点,谢谢了,先
用javascript 收集的好东西<script langauge="Javascript"> // 如果输入值为空,函数返回false function checkEmail(emailStr) { if (emailStr.length == 0) { alert("Email地址不正确"); return false; } var emailPat=/^(.+)@(.+)$/; var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; var validChars="\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$"); var matchArray=emailStr.match(emailPat); if (matchArray == null) { alert("Email地址不正确"); return false; } var user=matchArray[1]; var domain=matchArray[2]; if (user.match(userPat) == null) { alert("Email地址不正确"); return false; } var IPArray = domain.match(ipDomainPat); if (IPArray != null) { for (var i = 1; i <= 4; i++) { if (IPArray[i] > 255) { alert("Email地址不正确"); return false; } } return true; } var domainArray=domain.match(domainPat); if (domainArray == null) { alert("Email地址不正确"); return false; } var atomPat=new RegExp(atom,"g"); var domArr=domain.match(atomPat); var len=domArr.length; if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)) { alert("Email地址不正确"); return false; } if (len < 2) { alert("Email地址不正确"); return false; } return true; } </script>
/**
* <p>Checks if a field has a valid e-mail address.</p>
* <p>Based on a script by Sandeep V. Tamhankar ([email protected]),
* http://javascript.internet.com</p>
*
* @param value The value validation is being performed on.
*/
public static boolean isEmail(String value) {
boolean bValid = true; try {
String specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
String validChars = "[^\\s" + specialChars + "]";
String quotedUser = "(\"[^\"]*\")";
String atom = validChars + '+';
String word = "(" + atom + "|" + quotedUser + ")"; // Each pattern must be surrounded by /
String legalAsciiPat = getDelimittedRegexp("^[\\000-\\177]+$");
String emailPat = getDelimittedRegexp("^(.+)@(.+)$");
String ipDomainPat =
getDelimittedRegexp("^(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})$");
String userPat = getDelimittedRegexp("^" + word + "(\\." + word + ")*$");
String domainPat =
getDelimittedRegexp("^" + atom + "(\\." + atom + ")*$");
String atomPat = getDelimittedRegexp("(" + atom + ")"); Perl5Util matchEmailPat = new Perl5Util();
Perl5Util matchUserPat = new Perl5Util();
Perl5Util matchIPPat = new Perl5Util();
Perl5Util matchDomainPat = new Perl5Util();
Perl5Util matchAtomPat = new Perl5Util();
Perl5Util matchAsciiPat = new Perl5Util(); boolean ipAddress = false;
boolean symbolic = false; if (!matchAsciiPat.match(legalAsciiPat, value)) {
return false;
} // Check the whole email address structure
bValid = matchEmailPat.match(emailPat, value); if (value.endsWith(".")) {
bValid = false;
} // Check the user component of the email address
if (bValid) { String user = matchEmailPat.group(1); // See if "user" is valid
bValid = matchUserPat.match(userPat, user);
} // Check the domain component of the email address
if (bValid) {
String domain = matchEmailPat.group(2); // check if domain is IP address or symbolic
ipAddress = matchIPPat.match(ipDomainPat, domain); if (ipAddress) {
// this is an IP address so check components
for (int i = 1; i <= 4; i++) {
String ipSegment = matchIPPat.group(i);
if (ipSegment != null && ipSegment.length() > 0) {
int iIpSegment = 0;
try {
iIpSegment = Integer.parseInt(ipSegment);
} catch (Exception e) {
bValid = false;
} if (iIpSegment > 255) {
bValid = false;
}
} else {
bValid = false;
}
}
} else {
// Domain is symbolic name
symbolic = matchDomainPat.match(domainPat, domain);
} if (symbolic) {
// this is a symbolic domain so check components
String[] domainSegment = new String[10];
boolean match = true;
int i = 0;
int l = 0; while (match) {
match = matchAtomPat.match(atomPat, domain);
if (match) {
domainSegment[i] = matchAtomPat.group(1);
l = domainSegment[i].length() + 1;
domain =
(l >= domain.length()) ? "" : domain.substring(l);
i++;
}
} int len = i;
if (domainSegment[len - 1].length() < 2
|| domainSegment[len - 1].length() > 4) {
bValid = false;
} // Make sure there's a host name preceding the domain.
if (len < 2) {
bValid = false;
} } else {
bValid = false;
}
}
} catch (Exception e) {
bValid = false;
} return bValid;
}
// 如果输入值为空,函数返回false
function checkEmail(emailStr) {
if (emailStr.length == 0) {
alert("Email地址不正确");
return false;
}
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray == null) {
alert("Email地址不正确");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat) == null) {
alert("Email地址不正确");
return false;
}
var IPArray = domain.match(ipDomainPat);
if (IPArray != null) {
for (var i = 1; i <= 4; i++) {
if (IPArray[i] > 255) {
alert("Email地址不正确");
return false;
}
}
return true;
}
var domainArray=domain.match(domainPat);
if (domainArray == null) {
alert("Email地址不正确");
return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if ((domArr[domArr.length-1].length < 2) ||
(domArr[domArr.length-1].length > 3)) {
alert("Email地址不正确");
return false;
}
if (len < 2) {
alert("Email地址不正确");
return false;
}
return true;
}
</script>