Phone Number Validation Error

So I was finally able to get some phone number validation working. However, it only works in the interface and not when I'm actually using the record action.

Here's the code the error message I'm getting. I think this is happening because the record action relies on user input and perhaps starts off as null. I'm just hoping there's a way to fix it.

When I try to create a new contractor through the record action: Error Evaluating UI Expression Expression evaluation error [evaluation ID = 0932b:f622d] in rule 'ds_createcontractor' at function 'search' [line 65]: A null parameter has been passed as parameter 2.

                a!textField(
                  label: "Phone Number ",
                  labelPosition: "ABOVE",
                  placeholder: "### - ### - ####",
                  saveInto: ri!record['recordType!{d327a5dc-18d4-4ffd-8bdf-6a22b134677f}DS Contractor.fields.{f4c57b1e-a70b-4b5c-abfd-91fbfa77c38f}conPhoneNumber'],
                  refreshAfter: "UNFOCUS",
                  required: true,
                  value: ri!record['recordType!{d327a5dc-18d4-4ffd-8bdf-6a22b134677f}DS Contractor.fields.{f4c57b1e-a70b-4b5c-abfd-91fbfa77c38f}conPhoneNumber'],                 
                  validations: {if(
                    search("-", ri!record['recordType!{d327a5dc-18d4-4ffd-8bdf-6a22b134677f}DS Contractor.fields.{f4c57b1e-a70b-4b5c-abfd-91fbfa77c38f}conPhoneNumber'],8)<3,
                    "Please enter hyphens between the numbers.",
                    {}
                  )}
                  
                ),

Usually looks like this:

  Discussion posts and replies are publicly visible