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
Afzaal HassanAfzaal Hassan 

Retrieve Account name from search results in a lightning component

I am 95% done with writing a Lightning Component. What this app does is when a user types in a phone or name, it lists all the contact records associated with the search result. On of the columns is the account name associated with the contact. It also displays a radio button that you need to select. The only thing I have left to do is the following(and I am struggling to get it working):
If the account name starts with a P and a number, so P0232 - Greenwood, then I dont need to select the radio button. Currently, i have an error message popup when its not selected, which should only happen if the name was just Greenwood, for example. Not sure what to put in the conditional to make this work. Here is my code:

<div style="font-size: 20px">Customer Information</div>
        <tr style="width: 100%;">
                First Name: <lightning:input name="sFirstName" value="{!v.sFirst}"/>
                Last Name: <lightning:input name="sLastName" value="{!v.sLast}"/>
                Phone Number: <lightning:input name="sPhone" value="{!v.ani}"/>
            <td style="vertical-align:bottom;">
                <lightning:button label="Search" onclick="{!c.doConSearch}" />
    <br />
    <aura:if isTrue="{!v.hasContactResults}">
                <th>First Name</th>
                <th>Last Name</th>
                <th>Current Account</th>
                <th>Use This Contact</th>
            <aura:iteration items="{!v.contacts}" var="con">
                    <td><ui:inputRadio name="cons" label="{!con.Id}" labelClass="invis" change="{!c.onRadio}" /></td>
Here is the Controller:
doConSearch : function(component, event, helper) {
        component.set("v.selectedCon", "");
            var a = component.get('c.getCallQueue');
  createCase : function(component, event, helper) {
        component.set("v.hasErrors", false);
        component.set("v.errors", "");
        var studio = component.get("v.selectedCon");
        if(component.get("v.selectedStudio") || component.get("v.selectedOpp") || studio.Account.Name.contains('????')) {
            if(component.get("v.selectedCon") || (component.get("v.sFirst") && component.get("v.sLast") && component.get("v.ani"))){
            } else {
                component.set("v.hasErrors", true);
                component.set("v.errors", "Please select a Contact or enter a first name, last name, and phone");
        } else {
            component.set("v.hasErrors", true);
            component.set("v.errors", "Please select a studio or opportunity");
    onRadio: function(cmp, evt, helper) {
        var selected = evt.getSource().get("v.label");
        cmp.set("v.selectedCon", selected);
    selectStudio: function(cmp, evt, helper) {
        var selected = evt.getSource().get("v.label");
        cmp.set("v.selectedStudio", selected);

The if statement where you see the bold item is where the logic needs to go. I dont have the right syntax for the item in bold. Any help wuld be appreciated. Thanks
Valentin F.Valentin F.
Hi Afzaal,
You could use a regex :
\b - word boundary 
[a-zA-Z]{1} - 1 letter 
\d{4} - 4 digits

Let me know if it helped you.
Have a good day,