I just created below script, use it on field validate and see if this helps. You can handle more scenrios, if required.
var a=this.value.match(/^[0-9]{5}([- /]?[0-9]{4})?$/);
var b=this.value;
if(a!==null)
{
if((b.substring(5)!=='-')&&(b.length==9))
{
this.value=b.substring(0,5)+'-'+b.substring(5,b.length);
guideBridge.setFocus(first_name.somExpression);// set focus to some other form field
guideBridge.setFocus(this.somExpression);// set focus back to current field
}
else
{
this.value=this.value;
}
}
Sample Test Case
I/ P: Result
12345: Success
12345-6789: Success
123456789: Converted to 12345-6789 and then passed
1234: Fail
123456: Fail
12345-33: Fail
Thanks,
Mayank