Question
Wipro Ltd
IN
Last activity: 29 Apr 2019 0:47 EDT
How to persist the null value instead of special characters when user enters only special characters
Hi ,
I am working on a requirement where i need to persist the null value when user enters only special characters.
I am giving 2 scenarios here for more clarity :
Scenario 1:
First Name : @-=+|Ravi
this one am able to remove leading spl characters from a First Name property.
O/P : First Name : Ravi
Scenario 2 :
When user enters only special characters
First Name : @-=+|%
currently, this one is getting persisted in DB with spl chars, but that should not happend.
So, How can i persist the null value in DB instead of spl chars.
Please suggest is there any such regular expression which contains only special characters.
So that i can replace the regex with null value (" " )
Also attached screenshot for reference.
Thanks in Advance,
Ravi
***Edited by Moderator: Pallavi to update platform capability tags***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
IN
Can you try this function
stripNonAlphabeticChars
Coforge DPA
GB
Hi
Can you try using below :
@String.pxReplaceAllViaRegex(<Property-Name>,"[^a-zA-Z0-9]"," ")
Hope this helps.
Regards
Bhavya
Wipro Ltd
IN
Hi Bhavya,
Thanks for your response !!
On click of a save button, I should persist null value of all properties whichever contains only special chars on the work object.
Here, your regex function will work for specific property based on what property we referred in that function.
So, I am looking for a suggestion where all properties which contains only spl chars on the work object should be wiped out with null value.
Thanks,
Ravi
Coforge DPA
GB
Hi
If that is the case, then you need to create a common rule and use that for all properties.
Regards
Bhavya
Pegasystems Inc.
IN
Hello Ravi,
If you want to replace all the special characters then you need to use the regular expression to match the special character. You can then use replaceAll method from String class to replace it with the space. I had tried a sample use case to achieve your requirement.
1. Create a Edit Input rule as shown below for the property which you want to replace special characters with null.
2. In RecplaceSpecialChars rules, use regular expression to match all the special characters and replace with space. Below is the code and screen shot for the same.
if (theValue.length() > 0)
{
//use regular expression to match all the special characters and replace with space
theValue = theValue.replaceAll("[^\\w]"," ");
}
Hello Ravi,
If you want to replace all the special characters then you need to use the regular expression to match the special character. You can then use replaceAll method from String class to replace it with the space. I had tried a sample use case to achieve your requirement.
1. Create a Edit Input rule as shown below for the property which you want to replace special characters with null.
2. In RecplaceSpecialChars rules, use regular expression to match all the special characters and replace with space. Below is the code and screen shot for the same.
if (theValue.length() > 0)
{
//use regular expression to match all the special characters and replace with space
theValue = theValue.replaceAll("[^\\w]"," ");
}
3. Enter text with special characters like "@-=+|Ravi" and verify from database that the special characters are replaced with empty spaces.
4. Verify from database that the special characters are replaced with empty spaces.
Hope this helps.
Regards,
Waseem Khan
Pegasystems Inc.
IN
I have also tried by entering only special characters for the same property. Special characters got replaced by empty spaces. Please see below for the same.
Database:
Regards,
Waseem Khan
Wipro Ltd
IN
Hi Waseem,
Thanks for your response !!
But , I have a doubt, Do we need to add this Edit Input rule for each and every property wherever we need.
Currently am a writing a function where properties are not starts with px,py and pz.
here is the sample code :
java.util.Iterator itr = myStepPage.values().iterator();
while(itr.hasNext())
{
ClipboardProperty prop= (ClipboardProperty)itr.next();
String propname = prop.getName();
// String proptype = prop.getTypeName();
try{
if(!((propname.startsWith("px")) || (propname.startsWith("py")) || (propname.startsWith("pz"))))
{
String propvalue = prop.toString();
String newpropvalue="";
String regexStr = pega_rules_utilities.getDataSystemSetting("CLSBL","BLPortfolio/SpecialCharacterSet");
//String regexStr = "^[%+-=@|]+";
Hi Waseem,
Thanks for your response !!
But , I have a doubt, Do we need to add this Edit Input rule for each and every property wherever we need.
Currently am a writing a function where properties are not starts with px,py and pz.
here is the sample code :
java.util.Iterator itr = myStepPage.values().iterator();
while(itr.hasNext())
{
ClipboardProperty prop= (ClipboardProperty)itr.next();
String propname = prop.getName();
// String proptype = prop.getTypeName();
try{
if(!((propname.startsWith("px")) || (propname.startsWith("py")) || (propname.startsWith("pz"))))
{
String propvalue = prop.toString();
String newpropvalue="";
String regexStr = pega_rules_utilities.getDataSystemSetting("CLSBL","BLPortfolio/SpecialCharacterSet");
//String regexStr = "^[%+-=@|]+";
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexStr);
java.util.regex.Matcher matcher = pattern.matcher(propvalue);
while (matcher.find())
{
String replacementStr = "";
newpropvalue = matcher.replaceFirst(replacementStr);
prop.setValue(newpropvalue);
}
}
}
catch(Exception e)
{
oLog.error("Error in trimming special characters for Page - " + myStepPage + " and property name - " + propname);
}
}
So , I will try with ur regex pattern.
Thanks,
Ravi
Pegasystems Inc.
IN
Hello Ravi,
Yes you need to add this Edit Input rule for each and every property wherever you need.
Regards,
Waseem Khan
-
Sanjoy Bhattacharyya