Skip to main content
Known Participant
October 24, 2022
Question

Simple Javascript that adds "%" at end of entry if entry includes no "%"

  • October 24, 2022
  • 1 reply
  • 1111 views

I had this. I lost it. Now I can't replicate it. Help?

(FYI the code should exclude entries of "Share" and a "%" only. It should add a percent only to numbers 1-100)

 

I believe it was a custom format script looking like this:
if (event.value != "Share" && event.value != "%" && event.value == (/^[1-9][0-9]$|^[1-9]$|^100$/)) {event.target.value = event.value + "\%"}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
October 24, 2022

Use this:

 

if (/^\d{1,3}$/.test(event.value)) event.value+="%";

dankpoochAuthor
Known Participant
October 25, 2022

What does it mean if I paste the code above in custom format script, press ok, and it disappears, custom format category reverts to "None"?

Notably, I have 4 identical fields, appended by number, and three of these accept the code. 

try67
Community Expert
Community Expert
October 25, 2022

What exact code did you use?