cancel
Showing results for 
Search instead for 
Did you mean: 

Through error Validation in mapping

maheshp254
Discoverer
0 Kudos

hi friends

i have a requirement in mapping that from source system i am getting email id field

The email should have one ‘@’ character and one ‘.’ character – if the email is not having the

‘@’ or ‘.’ character, then replace it with ‘error’

How to validate this error?

please help me thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

vadimklimov
Active Contributor
0 Kudos

Hi Mahesh,

I would assume you need to verify if dot symbol exists after the at sign, but not anywhere in the e-mail address, right? If so, following UDF shall fulfil your requirement (assuming "eMailAddress" is a function argument of type String, which contains the validated e-mail address):


if (eMailAddress.matches("^.+@.+\\..+$")) {

     return eMailAddress;

} else {

     return "error";

}

It shall be noted that complete validation of an e-mail address has more checks than only verification of existence of the at and dot signs. So if you need to go ahead and implement more advanced validation of an e-mail address, then you may check one of 3rd party libraries and make use of them in the developed UDF. For example, you may want to check Apache Commons Validator (Validator – Commons Validator). Using this library, you can perform sophisticated e-mail address validation using following code snippet (assuming corresponding JAR file with the library has been imported and exposed to the UDF as well as respective class org.apache.commons.validator.routines.EmailValidator listed in imports section of the UDF):


EmailValidator validator = EmailValidator.getInstance();

if (validator.isValid(eMailAddress)) {

  return eMailAddress;

} else {

  return "error";

}

Regards,

Vadim

maheshp254
Discoverer
0 Kudos

hi Vadim,

thank you for your help it meet my requirment.

thank you.

Answers (0)