on 08-26-2013 2:56 PM
Hi,
I have a field A -I have to validate where the field value of A is proper Email or not like 1@x.com,1@x.co.in etc...
can i have the UDF for it. Please share the java program for Email id validation of a field.
I have to use graphical mapping and UDF for it.
Rgds
Hi SAP PI,
Please try the following UDF
public static String validate(String emailid){
if(emailid.matches("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"))
{
return "validEmail";
}
return "InvalidEmail";
}
Output
ebay@yahoo.com is validEmail
asho_ty5@xyz.com is validEmail
took is InvalidEmail
ywook@@34.com is InvalidEmail
wonder-abc@yahoo.com is validEmail
abc.@t.com is InvalidEmail
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi SAP PI,
Are you trying to check for multiple values for email validation and then return corresponding true / false.
In that case run a loop on the string array and call Baskar's or Anupam's method - one option can be:
for( int i = 0; i < emailid.length; i++)
{
String element = emailid[i];
try {
new InternetAddress(element
).validate();
result.addValue("true");
} catch (AddressException ex) {
result.addValue("false");
}
}
Hi SAP PI,
Just try this code
public void validate(String emailid[],ResultList result,Container container)throws StreamTransformationException{
for(int i=0;i<emailid.length;++i)
{
if(emailid[i].matches("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"))
{
result.addValue("validEmail");
}
else
{
result.addValue("InvalidEmail");
}
}
return;
}
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's easy. Use this link
http://stackoverflow.com/questions/13077897/java-email-address-validation
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public boolean isValidEmailAddress(String email) {
try {
new InternetAddress(email).validate();
} catch (AddressException ex) {
return false;
}
return true;
}
use this link for reference
http://docs.oracle.com/javaee/1.4/api/javax/mail/internet/InternetAddress.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check this program may be helpful.
package
com.java2novice.regex;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
public
class
MyEmailValidate {
private
static
Pattern emailNamePtrn = Pattern.compile(
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"
);
public
static
boolean
validateEmailAddress(String userName){
Matcher mtch = emailNamePtrn.matcher(userName);
if
(mtch.matches()){
return
true
;
}
return
false
;
}
Regards,
Nitin Patil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.