on 02-06-2016 1:32 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
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.