function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ForceLoverForceLover 

Visualforce Error....Exception: Matcher is not serializable.

Hello Everyone,

 

I want to check whether my one of inputtext field in a desired format or not ,in this case i'm getting the mentioned exception

 

Visualforce Error....Exception: Matcher is not serializable. 

 

i want my inputtext should be as   AANNNN-NNNNN (A= Alpha/Letter; N= Number) for eg: "AS1234-56789"

 

My Vf page:

 

<apex:page>

--------

<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!search}" rerender="resultsBlock" status="status"/>
</apex:panelGroup>

------------------------

</apex:page>

 

My controller:

 

i'm searching using matcher like this in my controller

 

 

Public class sitelead{

 

public string searchText {get;set;}

 

String REFIDRegex = '([a-zA-Z](2)[0-9](4)-[0-9](5))';
Pattern MyPattern = Pattern.compile(REFIDRegex);
Matcher MyMatcher = MyPattern.matcher(searchText);

 

}

sfdcfoxsfdcfox
You can't serialize Matchers because their state can't be serialized (they are compiled code fragments based on the input pattern). You will need to compile the pattern each time you intend to use it.
ForceLoverForceLover

Hi Sfdcfox,

 

Many thanks for your support to all...

 

can i use a javascript to validate my inputtext ? please help me with some sample code .........

 

 

ForceLoverForceLover

I'm struck here made changes to my code

 

<apex:inputText id="searchText" value="{!searchText}" onmousemove="checkingstring(this)"/>

 

<script>
function checkingstring(searchText){
var pattern = "([a-zA-Z](2)[0-9](4)-[0-9](5))";
var regexp = new System.Text.RegularExpressions.Regex(pattern);
var userInput = "(123) 555-1243";
if (!regexp.IsMatch($component.searchText))
{
alert("The syntax is always as follows: AANNNN-NNNNN (A= Alpha/Letter; N= Number) i.e. FL0301-12345</b>");

}
}
</script>

Bhawani SharmaBhawani Sharma
I am not very good in REGEX, but I can see here that you are just trying to validate the user input. If this is true, then you can simply add a javascript function, which will check for the first 2 character and the remaining digits.
You can call this onblur of search box, So user will the errors as he moved out his cursor.
sfdcfoxsfdcfox
Truthfully, you shouldn't depend on JavaScript validation, because it can be bypassed, then you're left with poor data going into the server. You can "pre-validate" with JavaScript, if you desire, but you should always validate input on the server.

The script you wrote doesn't appear to be standard JavaScript, so it's no wonder it doesn't work (that's .Net, if I'm not mistaken).

Just modify your Search function in the Apex Code to verify the input using a Matcher before attempting to search, if that is your intention. You can use ApexPages.addMessage to add an error to the page if the input is invalid.
ForceLoverForceLover

Hi sfdcfox,

 

yes, i followed your suggestion but i'm not getting the results,can you please look into this....

 

public class SiteLead {

 

public string searchText {get;set;}

 

public PageReference search() {


String REFIDRegex = '/^[A-Z]{2}\\d{4}-\\d{5}$/i';
Pattern MyPattern = Pattern.compile(REFIDRegex);
Matcher MyMatcher = MyPattern.matcher(searchText);

if (!MyMatcher.matches()) {

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'<b>The syntax is always as follows: AANNNN-NNNNN (A= Alpha/Letter; N= Number) i.e.FL0301-12345</b>'));
return null;
}
else{

searchResults1 = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText order by name];


if(searchResults1.size()==0){

LeadBackup__c lb = new LeadBackup__c(RefID_FileNumber__c = searchText,
Name=[select name,id from lead where Ref_ID_File_Number__c=:searchtext ].Name,
City__c=[select name,id,city from lead where Ref_ID_File_Number__c=:searchtext ].City,
Street__c=[select name,id,street from lead where Ref_ID_File_Number__c=:searchtext ].street,
State__c=[select name,id,state from lead where Ref_ID_File_Number__c=:searchtext ].state,
Lead__c = [select name,id from lead where Ref_ID_File_Number__c=:searchtext ].id,
Email__c = [select name,id,Email from lead where Ref_ID_File_Number__c=:searchtext ].Email,
Phone__c = [select name,id,Email,Phone from lead where Ref_ID_File_Number__c=:searchtext ].Phone,
Evening_Phone__c = [select name,id,Evening_Phone__c from lead where Ref_ID_File_Number__c=:searchtext ].Evening_Phone__c,
Preferred_Call_Time__c = [select name,id,Evening_Phone__c,Preferred_Call_Time__c from lead where Ref_ID_File_Number__c=:searchtext ].Preferred_Call_Time__c,
Notes__c = [select name,id,Evening_Phone__c,Notes__c from lead where Ref_ID_File_Number__c=:searchtext ].Notes__c,
Do_Not_Call__c = [select name,id,Evening_Phone__c,DoNotCall from lead where Ref_ID_File_Number__c=:searchtext ].DoNotCall);
system.debug('lb'+lb);
insert lb ;

searchResults = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText order by name];


}else{

ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Info,'<b>Please confirm name and address below. Address will be where the letter was received/addressed. If these do not match, you will need to re-verify Ref ID, as it may have been entered incorrectly</b>'));

searchResults = [select id,RefID_FileNumber__c,Name, Email__c, Phone__c, Street__c, City__c, State__c, TAB_Message__c, TAB_Time_stamp__c, Evening_Phone__c, Preferred_Call_Time__c, Notes__c,Do_Not_Call__c from LeadBackup__c where RefID_FileNumber__c =:searchText order by name];

return null;
}
return null;
}
}

 

 

}

sfdcfoxsfdcfox
You're trying to query the same thing as from the first time (in fact, you query it three times?), regardless, if your first query fails, then there is no LeadBackup__c record to query. You'll need to figure out a different logic to use.