Open GoogleCodeExporter opened 9 years ago
Original comment by apex.es...@gmail.com
on 11 Feb 2013 at 7:21
[deleted comment]
Proposed code
// validates whether a given string looks like an email address
// This is a simplified version of the the RFC which only matches the typical email address formats
// See http://en.wikipedia.org/wiki/Email_address#Examples for exotic examples that are only partially valid according to this regex
global static Boolean isValidEmail(String email) {
pattern validPattern = pattern.compile('^[A-Za-z0-9](([_\\+\\.\\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\\.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$');
matcher validMatcher = validPattern.matcher(email);
if (validMatcher.matches()) {
return true;
}
return false;
}
// validates whether a given string looks like a host
// examples "acme-international.com", "sales.acme-international.com", "mail.acme-international.uk.co"
global static Boolean isValidHost(String host) {
pattern validPattern = pattern.compile('^([A-Za-z0-9]+)(([\\.\\-]?[a-zA-Z0-9]+)*)\\.([A-Za-z]{2,})$');
matcher validMatcher = validPattern.matcher(host);
if (validMatcher.matches()) {
return true;
}
return false;
}
// validates whether a given string looks like a domain
global static Boolean isValidTopDomain(String topDomain) {
pattern validPattern = pattern.compile('^([A-Za-z0-9]+)(([\\-]?[a-zA-Z0-9]+)+)\\.([A-Za-z]{2,})$');
matcher validMatcher = validPattern.matcher(topDomain);
if (validMatcher.matches()) {
return true;
}
return false;
}
Original comment by sascha.k...@gmail.com
on 12 Feb 2013 at 4:10
Original issue reported on code.google.com by
sascha.k...@gmail.com
on 11 Feb 2013 at 4:29