Question
UTF characters problem over a validation rule
Hi guys!
I'm having a little bit problem. I'm making a Validation Rule to test an email address (because the PEGA validation only see if you've an "@", so it's not a valid one) using the "ñ" character (an special character from Spain. UTF-8) over the regular expresion. Nothings matter and the email is not validate it.
Ok... so I decided to replace all the "ñ" characters over the string (theValue) and then validate it without these characters... again, nothing matters.
Could you help me to improve something to do this? I'm over Pega 8.2.1 Cloud and i suppose that my cloud machine don't have the UTF8 encoding....
A testing email address (property value - text):
jaimeñherraiz@mail.test
The java code:
if (theValue== null || theValue.trim().equals("")) return false;
String mail = theValue.toString();
if (mail.indexOf("ñ") >0 ) { //"escaping" "ñ" character...
mail = mail.replace("ñ", "n");
}
//first pattern. Working fine over other plattform, don't at PEGA
//"^([a-z0-9ñ])+([a-z0-9._ñ-])*(@){1}([a-z0-9ñ]){1}(([a-z0-9_ñ-])((\\.){1}([a-z0-9_ñ-]))*)+((\\.){1}([a-z]){2,4})+$";
//second pattern
String regex = "^(?!\\.)(([^\\r\\\\]|\\\\[\\r\\\\])*|([-a-z0-9!#$%&'*+/=?^_`\\{|\\}~]|(?<!\\.)\\.)*)(?<!\\.)@[a-z0-9][\\w\\.-]*[a-z0-9]\\.[a-z][a-z\\.]*[a-z]$";
if (mail.matches(regex) ){
return true;
}else{
return false;
}
Thanks in advance!
***Edited by Moderator: Lochan to update platform capability tags***
Hi @JaimeH04,
You can resolve the issue either one of the below one.
1. The default encoding is based on the JVM settings, not anything in Pega. UTF-8 is a common default, but not guaranteed since your JVM might set another encoding.The easiest way to do this is to set the JVM level encoding using this Java option. This makes Pega encode everything in UTF-8 and will be the most consistent overall
-Dfile.encoding=UTF-8 .
2. In Dev Studio, open the Dynamic System Settings.