I would like to know if anyone has used a transform to add dashes to a phone number when it’s entered? So if the user types 2606093483 it will show as 260-609-3483.
def phone_format(n):
return format(int(n[:-1]), ",").replace(",", "-") + n[-1]
print phone_format('5551212')
print phone_format('8005551212')
Output:
555-1212
800-555-1212
>>>
That works if it is a parameter, but not when I type it in.
Then you will need another property to monitor, format, and write it back.
JCPhone_2021-09-17_1455.zip (3.3 KB)
script on props.text:
def phone_format(n):
return format(int(n[:-1]), ",").replace(",", "-") + n[-1]
value = str(currentValue.value)
if '-' not in value and len(value) >= 7:
self.custom.formattedText = phone_format(str(currentValue.value))
script on custom.formattedText:
if currentValue.value != self.props.text:
self.props.text = currentValue.value